question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception. on latest .NET 7

See original GitHub issue

Description

On our project on iOS this code throws an exception using latest .NET 7 Xcode 14.1, Xamarin.iOS 16.0.0.72, VS Version 17.5.0 Preview 1.0

Android and UWP are fine… Maui Sample project also works fine on iOS

builder.UseMauiApp<App>().ConfigureFonts(fonts =>
        {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
        })
        .UseMauiCommunityToolkit()
        .ConfigureEssentials(essentials =>
        {
            essentials.UseVersionTracking();
        });

Steps to Reproduce

Not sure

Link to public reproduction project repository

NA

Version with bug

7.0 (current)

Last version that worked well

7.0 Release Candidate 2

Affected platforms

iOS

Affected platform versions

iOS 15.4

Did you find any workaround?

No

Relevant log output

{System.TypeInitializationException: The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception.
 ---> System.MissingFieldException: Field not found: Microsoft.Maui.IPropertyMapper`2<Microsoft.Maui.IShapeView, Microsoft.Maui.Handlers.IShapeViewHandler> Microsoft.Maui.Handlers.ShapeViewHandler.Mapper Due to: Could not find field in class
   --- End of inner exception stack trace ---
   at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.RemapForControls(MauiAppBuilder builder)
   at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.SetupDefaults(MauiAppBuilder builder)
   at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.UseMauiApp[App](MauiAppBuilder builder)
   at AssessorApp.MauiProgram.CreateMauiApp() in C:\Users\User\workspace\project\MauiProgram.cs:line 13
   at AssessorApp.AppDelegate.CreateMauiApp() in C:\Users\User\workspace\project\project\Platforms\iOS\AppDelegate.cs:line 16
   at Microsoft.Maui.MauiUIApplicationDelegate.WillFinishLaunching(UIApplication application, NSDictionary launchOptions)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
   at AssessorApp.Program.Main(String[] args) in C:\Users\User\workspace\project\project\Platforms\iOS\Program.cs:line 15}
    base: {System.SystemException}
    TypeName: "Microsoft.Maui.Controls.Shapes.Shape"

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
mancdacommented, Nov 14, 2022

I ran into the same problem today as well.

2reactions
rolfbjarnecommented, Nov 17, 2022

It looks like the issue here is if you specify net7.0-ios15.4 as a TFM

I’m not sure if that’s supported. @rolfbjarne thoughts?

Yeah, that probably won’t work.

I’ve filed https://github.com/xamarin/xamarin-macios/issues/16802 to see if we can show a better error message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.TypeInitializationException: 'The type initializer for ' ...
System.TypeInitializationException: 'The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception.
Read more >
Why i am getting TypeInitializationException - Microsoft Q&A
TypeInitializationException: The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception. ---> System.
Read more >
Troubleshoot known issues - .NET MAUI
The solution to this issue on Windows is to uninstall the .NET MAUI workloads through the CLI, uninstall any .NET SDKs in Control...
Read more >
.NET MAUI - Microsoft Q&A
TypeInitializationException : 'The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception. So a bit of background, I'm working on ...
Read more >
.NET MAUI - Microsoft Q&A
TypeInitializationException: The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception. ---> System.MissingFieldException:… .NET MAUI.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found