Error on reloading a window after a second window is closed #763

Closed
opened 2026-01-29 16:47:55 +00:00 by claunia · 4 comments
Owner

Originally created by @dlitty on GitHub (Feb 17, 2022).

  • Version: latest (13.5.1)
  • .NET 5
  • Target: None; electronize start will reproduce

Using the latest Electron.NET API & CLI: if an application has two windows open, then one of them is closed, and you call Reload() on the first one, an error occurs:

A Javascript error occurred in the main process
Uncaught Exception: TypeError: Object has been destroyed
at BrowserWindow.<anonymous>( ... path ... /obj/Host/api/browserWindows.js:205:55 ...

Steps to Reproduce:

  1. Create a new .NET 5 ASP.NET web application
  2. Follow the instructions in the readme to set up Electron.NET in the project
  3. Instead of Task.Run(async () => await Electron.WindowManager.CreateWindowAsync());, use:
    Task.Run(async () => 
    {
        var mainWindow = await Electron.WindowManager.CreateWindowAsync();
        var secondWindow = await Electron.WindowManager.CreateWindowAsync();
        secondWindow.Close();
        mainWindow.Reload();
    }

Alternatively, comment out the Close and Reload lines, and manually close one window and hit Cmd-R on the other.

Originally created by @dlitty on GitHub (Feb 17, 2022). <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: latest (13.5.1) <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> * .NET 5 <!-- What target are you building for? --> * **Target**: None; `electronize start` will reproduce <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> Using the latest Electron.NET API & CLI: if an application has two windows open, then one of them is closed, and you call Reload() on the first one, an error occurs: ``` A Javascript error occurred in the main process Uncaught Exception: TypeError: Object has been destroyed at BrowserWindow.<anonymous>( ... path ... /obj/Host/api/browserWindows.js:205:55 ... ``` Steps to Reproduce: 1. Create a new .NET 5 ASP.NET web application 2. Follow the instructions in the readme to set up Electron.NET in the project 3. Instead of `Task.Run(async () => await Electron.WindowManager.CreateWindowAsync());`, use: ``` Task.Run(async () => { var mainWindow = await Electron.WindowManager.CreateWindowAsync(); var secondWindow = await Electron.WindowManager.CreateWindowAsync(); secondWindow.Close(); mainWindow.Reload(); } ``` Alternatively, comment out the Close and Reload lines, and manually close one window and hit Cmd-R on the other.
claunia added the bug label 2026-01-29 16:47:55 +00:00
Author
Owner

@danatcofo commented on GitHub (Feb 18, 2022):

Omg reproduction of a bug I couldn't figure out how to reproduce. And so simple! Thank you, you are my hero!

I'm going to fix this on Monday now that I have repo steps.

This bug has been on my annoyatron radar for months but never had the time to dive in depth to isolate and reproduce. Just happened randomly it seemed like.

@danatcofo commented on GitHub (Feb 18, 2022): Omg reproduction of a bug I couldn't figure out how to reproduce. And so simple! Thank you, you are my hero! I'm going to fix this on Monday now that I have repo steps. This bug has been on my annoyatron radar for months but never had the time to dive in depth to isolate and reproduce. Just happened randomly it seemed like.
Author
Owner

@dlitty commented on GitHub (Feb 19, 2022):

Glad I could help! Never good to have the annoyatron active!

@dlitty commented on GitHub (Feb 19, 2022): Glad I could help! Never good to have the annoyatron active!
Author
Owner

@xsoutline commented on GitHub (Aug 1, 2023):

I have the same problem


[Window Title]
Error

[Main Instruction]
A JavaScript error occurred in the main process

[Content]
Uncaught Exception:
TypeError: Object has been destroyed
    at BrowserWindow.<anonymous> (D:\AllProjects\WebApplication2\Browser\bin\Desktop\win-unpacked\resources\app.asar\api\browserWindows.js:190:55)
    at BrowserWindow.emit (node:events:526:28)
    at node:electron/js2c/browser_init:161:14116
    at process.processTicksAndRejections (node:internal/process/task_queues:78:11)

I opened window A when the application started with a custom url scheme, and then used the custom url scheme to open the program, triggering the second instance event. I called CreateWindowAsync to create a new window B, then closed window B. When I clicked on the link on in window A,the link has js listening on code, I reported this error.

After window B is closed, if I open a new window, this situation will disappear

@xsoutline commented on GitHub (Aug 1, 2023): I have the same problem ``` [Window Title] Error [Main Instruction] A JavaScript error occurred in the main process [Content] Uncaught Exception: TypeError: Object has been destroyed at BrowserWindow.<anonymous> (D:\AllProjects\WebApplication2\Browser\bin\Desktop\win-unpacked\resources\app.asar\api\browserWindows.js:190:55) at BrowserWindow.emit (node:events:526:28) at node:electron/js2c/browser_init:161:14116 at process.processTicksAndRejections (node:internal/process/task_queues:78:11) ``` I opened window A when the application started with a custom url scheme, and then used the custom url scheme to open the program, triggering the second instance event. I called CreateWindowAsync to create a new window B, then closed window B. When I clicked on the link on in window A,the link has js listening on code, I reported this error. After window B is closed, if I open a new window, this situation will disappear
Author
Owner

@FlorianRappl commented on GitHub (Nov 2, 2025):

Outdated - use ElectronNET.Core and ElectronNET.Core.AspNet.

See Wiki / What's New.

@FlorianRappl commented on GitHub (Nov 2, 2025): Outdated - use `ElectronNET.Core` and `ElectronNET.Core.AspNet`. See [Wiki / What's New](https://github.com/ElectronNET/Electron.NET/wiki/What's-New).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#763