MAUI IOS System.IO.FileNotFoundException throwing application even within try catch statement

403 views Asked by At

I have a MAUI app and after upgrading to .NET 7 it now crashes on startup. It throws error "System.IO.FileNotFoundException: 'Could not load file or assembly '/var/mobile/Containers/Data/Application/41E82FBF-FF2C-4A75-A2F7-6C0274110A4B/Documents/Acre.content/Xamarin.HotReload.Contracts.dll' or one of its dependencies.'"

The exception is thrown on UIApplication.Main(args, null, typeof(AppDelegate));

using ObjCRuntime;
using System.Diagnostics;
using UIKit;

namespace Acre;

public class Program
{
    // This is the main entry point of the application.
    static void Main(string[] args)
    {
        // if you want to use a different Application Delegate class from "AppDelegate"
        // you can specify it here.
        try
        {
            UIApplication.Main(args, null, typeof(AppDelegate));
        }
        catch (FileNotFoundException e)
        {
            Debug.WriteLine(e);
        }
    }
}

The try catch statement doesn't catch anything and the exception is thrown anyway. I think it may be an issue with something somewhere else in the code and it's just showing up here.

It also works in release mode perfectly fine, there is only an issue while debugging.

Any breakpoint put before the line where the exception is thrown is skipped.

I also tried to ignore the System.IO.FileNotFoundException in exception settings and disabled just my code which just threw a mono debugger error.

I just want to know how I can identify the actual issue.

1

There are 1 answers

1
Jessie Zhang -MSFT On

You can first try the following steps to troubleshoot the problem.

1.delete the obj folders and bin folders of every platform, then rebuild it.? If it doesn’t work,try to restart your visual studio.

2.if the problem persists,then right-click your project > Unload Project > right-click it again > Reload Project and check if this error disappears.