Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access a disposed object #119

Open
revenz opened this issue Feb 19, 2024 · 3 comments
Open

Cannot access a disposed object #119

revenz opened this issue Feb 19, 2024 · 3 comments

Comments

@revenz
Copy link

revenz commented Feb 19, 2024

Hi, just upgraded from version 2 to 3, now im getting this error on my second instance of the editor. I open the editor in one div, then i close that div, then create a completely new instance.

I put debug statements around every place I'm calling GetValue, its none of my calls to that, so I dont think I can gracefully handle this exception.

I've tried called DiposeEditor and Dispose on the Standalone editor but no change.

Any advice?

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Cannot access a disposed object. Object name: 'Microsoft.JSInterop.DotNetObjectReference`1[[BlazorMonaco.Editor.Editor, BlazorMonaco, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null]]'. System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Microsoft.JSInterop.DotNetObjectReference`1[[BlazorMonaco.Editor.Editor, BlazorMonaco, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null]]'. at Microsoft.JSInterop.DotNetObjectReference`1[[BlazorMonaco.Editor.Editor, BlazorMonaco, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null]].ThrowIfDisposed() at Microsoft.JSInterop.DotNetObjectReference`1[[BlazorMonaco.Editor.Editor, BlazorMonaco, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null]].get_Value() at BlazorMonaco.Editor.Global.Create(IJSRuntime jsRuntime, String domElementId, StandaloneEditorConstructionOptions options, EditorOverrideServices overrideServices, DotNetObjectReference`1 dotnetObjectRef) at BlazorMonaco.Editor.StandaloneCodeEditor.OnAfterRenderAsync(Boolean firstRender) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
@serdarciplak
Copy link
Owner

The get_Value method mentioned in the stack trace is not the GetValue method of the editor instance. So, it's not related to your GetValue calls.

According to the stack trace, the issue is not related to the first editor instance but the new one. Looks like the new editor is already disposed when it's rendered. This sounds like a reuse of the disposed first editor instance.

If you're not disposing anything manually, this may be related to Blazor's object instance management and how Blazor reuses the instances between renders. I would suggest checking the similar values you use between the first and the second editor instance to see if Blazor may think that they're actually the same instance and reuse the first instance.

@trungnt2910
Copy link

I got the same issue on a .NET 8 Blazor Web App.

Just make sure the code editor does not get rendered in the prerender phase.

@chrisonmoon
Copy link

Hello - i have the same Problem.

-> Just make sure the code editor does not get rendered in the prerender phase.

How I'm gonna do that ?

THank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants