Search code examples
maui

.NET MAUI: System.TypeInitializationException: 'The type initializer for 'Gdip' threw an exception'


Upon debugging my Android .NET MAUI application I get the message on the app startup:

.NET MAUI: System.TypeInitializationException: 'The type initializer for 'Gdip' threw an exception'

and the app crashes. Call stack does not have any helpful info:

screenshot

I do not use System.Drawing.Common in my application as it is not compatible.

How can I fix this issue?


Solution

  • In your MAUI Application project, at the project root level add the file runtimeconfig.template.json.

    screenshot

    the file should contain this json:

    {
      "configProperties": {
        "System.Drawing.EnableUnixSupport": true
      }
    }
    

    After that clean and rebuild the project.