maui icon indicating copy to clipboard operation
maui copied to clipboard

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

Open paulhavey opened this issue 3 years ago • 2 comments
trafficstars

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"

paulhavey avatar Nov 14 '22 05:11 paulhavey

Hi @paulhavey. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 14 '22 15:11 ghost

I ran into the same problem today as well.

mancda avatar Nov 14 '22 17:11 mancda

I ran into the same problem today as well.

Could you share more information or a small sample where reproduce the issue?

jsuarezruiz avatar Nov 15 '22 10:11 jsuarezruiz

Hi @paulhavey. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 15 '22 19:11 ghost

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?

PureWeen avatar Nov 16 '22 17:11 PureWeen

Sorry this took so long.

about

packages

mancda avatar Nov 16 '22 22:11 mancda

I am targeting a Mac running Ventura OS and targeting the IPhone 14 Plus IOS 16 Simulator.

mancda avatar Nov 16 '22 22:11 mancda

@mancda can you paste your csproj file here? and/or attach a binlog? https://github.com/xamarin/xamarin-macios/wiki/Diagnosis

PureWeen avatar Nov 16 '22 22:11 PureWeen

See attached. binlogandcsproj.zip

mancda avatar Nov 17 '22 14:11 mancda

@mancda you need to change this

image

remove the 15.4 from net7.0-ios

PureWeen avatar Nov 17 '22 16:11 PureWeen

Hi @paulhavey. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 17 '22 16:11 ghost

That fixed it for me. Thank you very much.

mancda avatar Nov 17 '22 17:11 mancda

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.

rolfbjarne avatar Nov 17 '22 17:11 rolfbjarne

Closing this issue in favor of https://github.com/xamarin/xamarin-macios/issues/16802

I've also engaged with the IDE teams on this one to provide a better experience with the TFM dropdown options.

PureWeen avatar Nov 17 '22 18:11 PureWeen