Toolbelt.Blazor.HotKeys2
Toolbelt.Blazor.HotKeys2 copied to clipboard
Microsoft.JSInterop.JSException: JS object instance with ID 7 does not exist (has it been disposed?).
Hi @jsakamoto,
When I was testing ilovedotnet using MAUI Blazor Hybrid, I noticed that the below error occurs when I navigate to blogs/step-by-step-setup-guide-for-dotnet-maui-with-visual-studio-code. The corresponding razor page MAUISetup.razor sits inside MAUIDemoComponents.razor project. I don't have any usage of the hotkeys inside this page but I get the below exception.
Microsoft.JSInterop.JSException: JS object instance with ID 7 does not exist (has it been disposed?).
E@app://0.0.0.1/_framework/blazor.webview.js:1:5123
@app://0.0.0.1/_framework/blazor.webview.js:1:2886
Promise@[native code]
beginInvokeJSFromDotNet@app://0.0.0.1/_framework/blazor.webview.js:1:2859
@app://0.0.0.1/_framework/blazor.webview.js:1:47081
@user-script:1:4:75
forEach@[native code]
@user-script:1:4:45
global code@app://0.0.0.1/blogs/step-by-step-setup-guide-for-dotnet-maui-with-visual-studio-code:1:26
at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
at Toolbelt.Blazor.HotKeys2.HotKeysContext.<>c__DisplayClass65_0.<<UnregisterAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Toolbelt.Blazor.HotKeys2.Extensions.JS.InvokeSafeAsync(Func`1 action, ILogger logger)
Toolbelt.Blazor.HotKeys2.HotKeys: Error: JS object instance with ID 7 does not exist (has it been disposed?).
E@app://0.0.0.1/_framework/blazor.webview.js:1:5123
@app://0.0.0.1/_framework/blazor.webview.js:1:2886
Promise@[native code]
beginInvokeJSFromDotNet@app://0.0.0.1/_framework/blazor.webview.js:1:2859
@app://0.0.0.1/_framework/blazor.webview.js:1:47081
@user-script:1:4:75
forEach@[native code]
@user-script:1:4:45
global code@app://0.0.0.1/blogs/step-by-step-setup-guide-for-dotnet-maui-with-visual-studio-code:1:26
Microsoft.JSInterop.JSException: JS object instance with ID 7 does not exist (has it been disposed?).
E@app://0.0.0.1/_framework/blazor.webview.js:1:5123
@app://0.0.0.1/_framework/blazor.webview.js:1:2886
Promise@[native code]
beginInvokeJSFromDotNet@app://0.0.0.1/_framework/blazor.webview.js:1:2859
@app://0.0.0.1/_framework/blazor.webview.js:1:47081
@user-script:1:4:75
forEach@[native code]
@user-script:1:4:45
global code@app://0.0.0.1/blogs/step-by-step-setup-guide-for-dotnet-maui-with-visual-studio-code:1:26
at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
at Toolbelt.Blazor.HotKeys2.HotKeysContext.<>c__DisplayClass73_0.<<DisposeAsync>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Toolbelt.Blazor.HotKeys2.Extensions.JS.InvokeSafeAsync(Func`1 action, ILogger logger)
This can be reproduced from latest clone of ilovedotnet repo. Please can you assist me on what is the issue here?
Thanks, @fingers10
Hi @fingers10, Unfortunately, I could not build the "MAUI" project with the build error below.
24>------ Rebuild All started: Project: MAUI, Configuration: Debug Any CPU ------
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: The "DefineStaticWebAssetEndpoints" task failed unexpectedly.
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: System.ArgumentException: An item with the same key has already been added.
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.Execute()
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
24>C:\Program Files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
24>Done building project "CommonComponents.csproj" -- FAILED.
========== Rebuild All: 23 succeeded, 1 failed, 0 skipped ==========
I have no idea why such a build error happened. I used the commit 96b9ced87d37a4f0e66c646795971b2d4b5dc7c2 on your "ilovedotnet" repository for that build.
When I created a new .NET 9 MAUI Blazor Hybrid App project and ran the Windows platform on my latest version of Visual Studio 2022, it worked correctly. So that I think my development environment must not bad.
Anyway, I could not reproduce your problem on my side since the above error. If you can provide me a small sample MAUI Blazor Hybrid app that reproduces the problem, I can investigate it.
Ah I understand the problem. @jsakamoto Can you do the following and do a build?
- From the project root, switch to
cd CommonComponents. - Now run
npm install - Now try building the project.
The build is failing because of this following code in CommonComponents.csproj or you can simply comment the below lines inside the CommonComponents.csproj.
<Target Name="CopyChartCSS" BeforeTargets="PreBuildEvent">
<!-- https://jeremybytes.blogspot.com/2020/05/cross-platform-build-events-in-net-core.html -->
<ItemGroup>
<DataFiles Include="$(ProjectDir)\node_modules\charts.css\dist\charts.min.css" />
</ItemGroup>
<Copy SourceFiles="@(DataFiles)" DestinationFolder="$(ProjectDir)\wwwroot\css\" SkipUnchangedFiles="true" />
</Target>
Thanks for pointing out. I'll add a fix. I think this should help you to build and debug the HotKey issue.
@fingers10
Can you do the following and do a build?
I did it, including commenting out the "CopyChartCSS" target in the CommonComponents.csproj, but the build is still failing.😭
The .NET SDK version is 9.0.200 in my environment
$ dotnet --version
9.0.200
@jsakamoto I was preparing a clean branch for you to proceed. But surprisingly I'm not able to reproduce the issue. I'm not sure what happened. I faced this issue several times yesterday. May be running dotnet clean might have fixed it. I'll keep an eye for a week to see if this issue occurs again. Else I'll come back and close this issue.
@fingers10 OK, no problem. If you find any issues with this library, please let me know.😊
Hi @fingers10, I'm going to close this issue to keep the issue list clean. But of course, as you know, please feel free to reopen this issue or create a new one as needed.
Anyway, thank you for your contributions!