aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

[.NET 6 Blazor server] can't catch properly an ObjectDisposedException when stream from c# to Js

Open julienGrd opened this issue 4 years ago • 4 comments

Hello guys, I had a bug on my code which thrown an "System.ObjectDisposedException: Cannot access a closed Stream", when i was sending a stream to js.

The error was pretty clear, i was trying to consume a stream already consumed.

but anyway, i saw the exception was not catch so it let the app in a incoherent State.

I have an ErrorBoundary also in the app which was not updated.

I see anyway the error in the chrome console. [2021-12-14T11:21:57.920Z] Error: System.ObjectDisposedException: Cannot access a closed Stream. at System.IO.MemoryStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.MemoryStream.ReadAsync(Memory1 buffer, CancellationToken cancellationToken) --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost.<>c__DisplayClass46_0.<<SendDotNetStreamAsync>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c__111.<<InvokeAsync>b__11_0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost.SendDotNetStreamAsync(DotNetStreamReference dotNetStreamReference, Int64 streamId, Byte[] buffer)

I now manage how to deal to avoid this exception, but im wonder why it can't be catch properly and let the app in inchoherent state.

To reproduce:

  • Create a MemoryStream in the initialized of a component
  • on a button click, send the stream to the js (surround with try catch)
  • click again on the button, you will have the app broken

julienGrd avatar Dec 14 '21 11:12 julienGrd

Hi @julienGrd, thanks for reaching out. I was able to reproduce and got the Error: System.ObjectDisposedException: Cannot access a closed Stream exception in the console log. This was an Unhandled Exception and the circuit was crushed. I agree this seems a bit odd, as I would've expected the error boundary to trigger as well. Marking as bug.

TanayParikh avatar Dec 14 '21 17:12 TanayParikh

Interestingly, doing something like _ = await JS.InvokeAsync<string>("nonExistantFunction"); upon button press doesn't crush the circuit and successfully triggers the error boundary.

TanayParikh avatar Dec 14 '21 17:12 TanayParikh

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost avatar Dec 14 '21 17:12 ghost

Thank you for filing this issue. In order for us to investigate this issue further, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem.

mkArtakMSFT avatar Aug 10 '22 16:08 mkArtakMSFT

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost avatar Oct 06 '23 17:10 ghost

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

mkArtakMSFT avatar Dec 14 '23 18:12 mkArtakMSFT

I think my issue #53376 is also partially related to this. The difference is I don't try to access a closed / consumed stream but also get an exception I'm unable to catch.

Tyme-Bleyaert avatar Jan 17 '24 10:01 Tyme-Bleyaert