iOS The type initializer for 'Microsoft.Maui.Controls.Shapes.Shape' threw an exception. on latest .NET 7
See original GitHub issueDescription
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:
- Created 10 months ago
- Comments:14 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I ran into the same problem today as well.
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.