Iris Classon
Iris Classon - In Love with Code

Resolving the Token 2001530 Is Not Valid Error in NET MAUI

Today, Monday, I encountered a new bug that appeared after switching between two branches—one targeting Xamarin.Forms and the other .NET MAUI. While I was able to build the .NET MAUI app for Android, the iOS build crashed in AppDelegate with the following error:

System.ArgumentOutOfRangeException: Token 2001530 is not valid in the scope of module Microsoft.iOS.dll. (Parameter 'metadataToken')

This error was caught and logged, revealing an issue in the Main method of the iOS application:

public class Application
{
    private static void Main(string[] args)
    {
        try
        {
            UIApplication.Main(args, null, typeof(AppDelegate));
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            FileLogger.MakeSureAllLogsAreWritten();
            throw;
        }
    }
}

The error message suggested that an incorrect or outdated version of a library was being referenced. This kind of issue is often resolved by following these steps:

1. **Manually remove** the `bin` and `obj` folders.
2. Run a **NuGet restore**.
3. **Rebuild** the project.

Sure enough, after following these steps, the app built successfully. Hopefully, this quick fix helps anyone else encountering this error!

Comments

Leave a comment below, or by email.

Last modified on 2024-11-04

comments powered by Disqus