From 94ba24a03ef781af5c86ee51df11ef3d677c5772 Mon Sep 17 00:00:00 2001 From: lindexi Date: Sun, 1 Aug 2021 18:46:59 +0800 Subject: [PATCH 1/2] Fix create BitmapDecoder with async file stream. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [BitmapDecoder.Create does not handle FileStream with FileOptions.Asynchronous · Issue #4355 · dotnet/wpf](https://github.com/dotnet/wpf/issues/4355 ) --- .../System/Windows/Media/Imaging/BitmapDecoder.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs index 165353e529d..ba6e0c2cbcd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs @@ -1138,14 +1138,22 @@ out SafeFileHandle safeFilehandle if (stream is System.IO.FileStream) { System.IO.FileStream filestream = stream as System.IO.FileStream; - try { - safeFilehandle = filestream.SafeFileHandle; + if (filestream.IsAsync is false) + { + safeFilehandle = filestream.SafeFileHandle; + } + else + { + // If Filestream is async that doesn't support IWICImagingFactory_CreateDecoderFromFileHandle_Proxy, then revert to old code path. + safeFilehandle = null; + } } catch { // If Filestream doesn't support SafeHandle then revert to old code path. + // See https://github.com/dotnet/wpf/issues/4355 safeFilehandle = null; } } From 580095a9cdfc8ed8d5887f608131dbfd9a1b5753 Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 12 Jul 2022 09:59:41 +0800 Subject: [PATCH 2/2] Add comment --- .../System/Windows/Media/Imaging/BitmapDecoder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs index ba6e0c2cbcd..2eea582d5a6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs @@ -1146,7 +1146,7 @@ out SafeFileHandle safeFilehandle } else { - // If Filestream is async that doesn't support IWICImagingFactory_CreateDecoderFromFileHandle_Proxy, then revert to old code path. + // The IWICImagingFactory_CreateDecoderFromFileHandle_Proxy do not support async Filestream, so we revert to old code path. safeFilehandle = null; } }