dotnet / dotnet/wpf

Exception in Stream.Close method causes AppDomain to unload while downloading a Bitmap

Open
#2,960 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

Case: While using a custom non-seeking `Stream` as a parameter for `BitmapFrame.Create` and if that stream throws exception in `Stream.Close` function then the thread running async read-callback function causes the AppDomain to unload.

Such that, even if we register to `AppDomain.CurrentDomain.UnhandledException` the event is triggered with `IsTerminating` set to `true`. We can do nothing but log.

I have attached a sample project [CsBitmapDownloadBug.zip](https://github.com/dotnet/wpf/files/4561759/CsBitmapDownloadBug.zip) that trigger the exception on the following line:

https://github.com/dotnet/wpf/blob/ac9d1b7a6b0ee7c44fd2875a1174b820b3940619/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs#L310

Note-1: Similar error could still happen for any code outside try/catch block in the read-callback function such as output-stream operations.
Note-2: in .NET Framework I did hit a similar issue with WCF streams, where when the server is faulted during download, my client app disappeared.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.