Object reference not set to an instance of an object. [mono-rt] at FFImageLoading.Maui.CachedImage.SetupOnBeforeImageLoading

Sreejith Sreenivasan 791 Reputation points
2024-06-05T08:13:02.5633333+00:00

I am getting below exception when loading my MAUI application.

System.NullReferenceException: 'Object reference not set to an instance of an object.'
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]    at FFImageLoading.Maui.CachedImage.SetupOnBeforeImageLoading(TaskParameter& imageLoader, IImageSourceBinding source, IImageSourceBinding loadingPlaceholderSource, IImageSourceBinding errorPlaceholderSource)
[mono-rt]    at FFImageLoading.Maui.Platform.CachedImageHandler.UpdateBitmap(CachedImageView imageView, CachedImage image, CachedImage previousImage)
[mono-rt]    at FFImageLoading.Maui.Platform.CachedImageHandler.ConnectHandler(CachedImageView platformView)
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler`2[[FFImageLoading.Maui.CachedImage, FFImageLoading.Compat.Maui, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null],[FFImageLoading.Maui.Platform.CachedImageView, FFImageLoading.Compat.Maui, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null]].OnConnectHandler(View platformView) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 76
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler.OnConnectHandler(Object platformView) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandler.cs:line 204
[mono-rt]    at Microsoft.Maui.Handlers.ElementHandler.ConnectHandler(Object platformView) in D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 106
[mono-rt]    at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 64
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler`2[[FFImageLoading.Maui.CachedImage, FFImageLoading.Compat.Maui, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null],[FFImageLoading.Maui.Platform.CachedImageView, FFImageLoading.Compat.Maui, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 53
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler`2[[FFImageLoading.Maui.CachedImage, FFImageLoading.Compat.Maui, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null],[FFImageLoading.Maui.Platform.CachedImageView, FFImageLoading.Compat.Maui, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56
[mono-rt]    at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 921
[mono-rt]    at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 863
[mono-rt]    at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:line 2031
[mono-rt]    at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 96
[mono-rt]    at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 127
[mono-rt]    at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\Layout\LayoutHandler.Android.cs:line 41
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56

I have created a sample demo with this issue

I have issue with redirecting the pages to MainPage or HomePage. If I load the MainPage from App.xaml.cs like below no issue.

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new MainPage();
    }
}

But if I load the HomePage from App.xaml.cs like below I am getting the above exception related to FFImageLoading.

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new HomePage();
    }
}

HomePage has one ffimageloading widget and I have added .UseFFImageLoading() property on the MauiProgram.cs.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,091 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sreejith Sreenivasan 791 Reputation points
    2024-06-06T15:42:47.9266667+00:00

    From the error log, I found some keyword about FFImageLoading.Compat.Maui. But I had already changed all namespace about FFImageLoading.Compat.Maui to FFImageLoading.Maui. Are you using the right lib from https://www.nuget.org/packages/FFImageLoading.Maui.

    Maybe you can try some actions like below:

    1. Add the right lib FFImageLoading.Maui to your project.
    2. Delete obj folder and Rebuild the solution.
    3. Upload a simple demo project here. I will take a deeper look.

    https://github.com/microspaze/FFImageLoading.Maui/issues/39

    0 comments No comments