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

[Windows] PlatformImage.FromStream crash #18954

Closed
nor0x opened this issue Nov 22, 2023 · 4 comments · Fixed by #23824
Closed

[Windows] PlatformImage.FromStream crash #18954

nor0x opened this issue Nov 22, 2023 · 4 comments · Fixed by #23824

Comments

@nor0x
Copy link
Contributor

nor0x commented Nov 22, 2023

Description

trying to get an image from the web as an IImage like this:

var imageUrl = "https://source.unsplash.com/random";
var stream = await new HttpClient().GetStreamAsync(imageUrl);
var img = PlatformImage.FromStream(stream);

crashes the app on Windows with the following Exception:

   at System.IO.WindowsRuntimeStreamExtensions.AsRandomAccessStream(Stream stream)
   at Microsoft.Maui.Graphics.Platform.PlatformImage.<>c__DisplayClass18_0.<<FromStream>b__0>d.MoveNext()
   at Microsoft.Maui.Graphics.Platform.AsyncPump.Run[T](Func`1 asyncMethod)
   at Microsoft.Maui.Graphics.Platform.PlatformImage.FromStream(Stream stream, ImageFormat format)
   at MyApp.Pages.MainPage.<OnMounted>d__6.MoveNext() in C:\dev\MyApp\MainPage.cs:line 64
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 1914
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()

Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking.

Works fine on Android

Repro:
MauiApp1.zip

Steps to Reproduce

  1. create maui app
  2. use PlatformImage.FromStream
  3. run on windows

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows

Did you find any workaround?

No response

Relevant log output

No response

@nor0x nor0x added the t/bug Something isn't working label Nov 22, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Nov 22, 2023
@kevinxufei
Copy link

Verified this issue with Visual Studio 17.10.0 Preview 3 (8.0.20 & 8.0.0-rc.2.9530). Can not repro it with sample project

@kevinxufei kevinxufei added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Apr 12, 2024
@nor0x
Copy link
Contributor Author

nor0x commented Apr 16, 2024

@kevinxufei how did you test?

I just downloaded the repro project, updated to the latest maui nuget packages and I'm still able to reproduce this:
image

   at System.IO.WindowsRuntimeStreamExtensions.AsRandomAccessStream(Stream stream)
   at Microsoft.Maui.Graphics.Platform.PlatformImage.<>c__DisplayClass18_0.<<FromStream>b__0>d.MoveNext()
   at Microsoft.Maui.Graphics.Platform.AsyncPump.Run[T](Func`1 asyncMethod)
   at Microsoft.Maui.Graphics.Platform.PlatformImage.FromStream(Stream stream, ImageFormat format)
   at MauiApp1.MainPage.<OnCounterClicked>d__2.MoveNext() in C:\dev\MauiApp1\MauiApp1\MainPage.xaml.cs:line 22

I'm on .NET 8 version 8.0.300-preview.24203.14 and I have referenced the following MAUI packages:

<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.20" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.20" />

@dotnet-policy-service dotnet-policy-service bot removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Apr 16, 2024
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@jsuarezruiz jsuarezruiz added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jun 6, 2024
@nor0x
Copy link
Contributor Author

nor0x commented Jun 6, 2024

updated my repro to 8.0.40. The exception is the same - is this something that even was adressed at all in a recent release @jsuarezruiz ?
image

@dotnet-policy-service dotnet-policy-service bot removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jun 6, 2024
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 6, 2024
@MartyIX
Copy link
Contributor

MartyIX commented Jul 16, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants
@Eilon @MartyIX @nor0x @jsuarezruiz @samhouts @kevinxufei and others