Open NishiokaTakeo opened 10 months ago
It could FindMauiContext()
returns null.
Is it supported already in .net 8 maui? I raised an issue about it and it's coming
@NishiokaTakeo I have reviewed your merge request, your code can prevent NRE but still not fix the cause of NRE. The better fix is to find out why FindMauiContext() returns null. Can you upload the full demo project then I can take a deeper look for this issue.
I found this to be the case in my app because I was setting MainPage
for my App class too early. Application.Current.Handler
wasn't set yet when I was setting MainPage
and that caused FindMauiContext()
to return null
.
I worked around this by setting MainPage
in an overload of CreateWindow
in my application class. By that time, Application.Current.Handler
was properly set. The takeaway is that you have to be conscious of when your pages that have CachedImages on them are being created. It's at that time that FindMauiContext()
is being called.
This probably is not the solution but perhaps it gives some insight as to why FindMauiContext()
might be returning null
. It might not be looking in the right places, or in the right places at quite the right time.
Hi @brunck , Thanks for reply and the workaround works for my case as well.
I was setting MainPage for my App class too early. Application.Current.Handler wasn't set yet when I was setting MainPage and that caused FindMauiContext() to return null.
@microspaze,
As @brunck pointed out, I think FFImageLoading.Maui
library should take care into above case and the library should not throw exception.
MS document supposes to set MainPage in App constructor. But not strongly mention as xamarin document does.
For Xamarin, document mentioned,
The MainPage property should be set in the App constructor,
It would be great if you revaluate PR goes in.
I have merged the push request. Thanks very much!
The latest version 1.0.7 has been uploaded to NUGET. You can try it to verify this issue.
Had this problem in an application, and the workaround posted from @brunck helped out.
After updating FFImageLoading.Maui to 1.0.7 and reverting the workaround changes, the app is working as expected and images are showing up normally.
I confirmed the issue does not happen. Thank you for fixing!
@NishiokaTakeo
Since version 1.2.6 the problem has returned ImageService.Instance is null
In version 1.2.5 is good
Please check this
@Jasper7 I really don't know what had been changed in Maui. But if you upgrade Maui to the latest version, then those weird problems will all disappear. JUST TRY: sudo dotnet workload update
Description
ImageService is null as a result, it causes NullReferenceException.
Steps to Reproduce
Add a file contains below.
Set
Source
binding property from behind the code. At this time, It wasStream
. but it does not matter asImageService
was null.Expected Behavior
Should not throws NullReferenceException.
Actual Behavior
throws NullReferenceException.
Basic Information
Screenshots