Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] TypeLoadException in MacCatalyst #1195

Closed
2 tasks done
gktval opened this issue May 19, 2023 · 12 comments
Closed
2 tasks done

[BUG] TypeLoadException in MacCatalyst #1195

gktval opened this issue May 19, 2023 · 12 comments
Labels
bug Something isn't working not-reproduced Couldn't reproduce the bug unverified

Comments

@gktval
Copy link

gktval commented May 19, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

In a brand new Maui project on MacCatalyst, I am getting a TypeLoadException when the program starts up. The error message says:

"Could not set up parent class, due to: Invalid generic instantiation assembly:/bin/Debug/net7.0-maccatalyst/maccatalyst-x64/SkiaSharpTest.app/Contents/MonoBundle/Microsoft.Maui.dll type:ViewHandler`2 member:(null)"

The source of the error says it is from CommunityToolkit.Maui. here is the stack trace

" at CommunityToolkit.Maui.AppBuilderExtensions.<>c.b__0_0(IMauiHandlersCollection h) in /_/src/CommunityToolkit.Maui/AppBuilderExtensions.shared.cs:line 28\n at Microsoft.Maui.Hosting.HandlerMauiAppBuilderExtensions.HandlerRegistration.AddRegistration(IMauiHandlersCollection builder)\n at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.CreateHandlerCollection(IEnumerable1 registrationActions)\n at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory..ctor(IEnumerable1 registrationActions)\n at Microsoft.Maui.Hosting.HandlerMauiAppBuilderExtensions.<>c.b__1_0(IServiceProvider sp)\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)\n at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)\n at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)\n at System.Collections.Concurrent.ConcurrentDictionary2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type key, Func2 valueFactory)\n at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)\n at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)\n at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)\n at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)\n at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)\n at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IMauiHandlersFactory](IServiceProvider provider)\n at Microsoft.Maui.MauiContext.<.ctor>b__2_0()\n at System.Lazy1[[Microsoft.Maui.IMauiHandlersFactory, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ViaFactory(LazyThreadSafetyMode mode)\n at System.Lazy1[[Microsoft.Maui.IMauiHandlersFactory, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)\n at System.Lazy1[[Microsoft.Maui.IMauiHandlersFactory, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].CreateValue()\n at System.Lazy`1[[Microsoft.Maui.IMauiHandlersFactory, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_Value()\n at Microsoft.Maui.MauiContext.get_Handlers()\n at Microsoft.Maui.Platform.ElementExtensions.SetHandler(INativeObject nativeElement, IElement element, IMauiContext context)\n at Microsoft.Maui.Platform.ElementExtensions.SetApplicationHandler(IUIApplicationDelegate platformApplication, IApplication application, IMauiContext context)\n at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)\n at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)\n at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)\n at SkiaSharpTest.Program.Main(String[] args) in /Users/gktval/Projects/SkiaSharpTest/Platforms/MacCatalyst/Program.cs:line 13"

Any ideas what I can do to resolve this? It seems like this just started happening after updating to Maui 7.0.86.

Expected Behavior

No error

Steps To Reproduce

Create a new Maui Project in Visual Studio. Add CommunityToolkit.Maui nugget. Debug for MacCatalyst.

Link to public reproduction project repository

NA

Environment

- .NET MAUI CommunityToolkit: 5.0 and 5.1
- OS:MacCatalyst
- .NET MAUI: 7.0.86

Anything else?

No response

@gktval gktval added bug Something isn't working unverified labels May 19, 2023
@gktval
Copy link
Author

gktval commented May 23, 2023

I see this similar issue. CommunityToolkit needs updated to the new version of Maui.

#1075

Is it possible to get a new release that support 7.0.86, please.

@ghost
Copy link

ghost commented May 23, 2023

Hi @gktval. We have added the "needs reproduction" label to this issue, which indicates that we cannot take further action. This issue will be closed automatically in 5 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.

@gktval
Copy link
Author

gktval commented May 23, 2023

Just create a brand new Maui Project and add CommunityToolkit in Mac. If you need a reproduction for a new project in Visual Studio, I will put one together... Or use any of the sample ones in this repository
https://github.com/CommunityToolkit/Maui/tree/main/samples

@gktval
Copy link
Author

gktval commented May 23, 2023

Here is a link to a brand new project https://github.com/gktval/MauiCommunityToolkitError that the error occurs in.

@vhugogarcia
Copy link
Contributor

Hello @gktval ,

I downloaded your brand new project where you say the error occurs, however, I was unable to reproduce it locally.

Please make sure you are using the follow app versions in macOS:

  • Visual Studio Community 2022 for Mac, Version 17.5.6 (build 3)
  • .NET SDK (Arm64), Versions: 7.0.302
  • Xamarin.Mac, Version: 9.3.0.6
  • XCode 14.3
  • macOS Ventura 13.4
  • Xamarin.iOS, Version: 16.4.0.6

And that you have installed the following workloads:
image

I ran your demo project without issues. 😃

Regards,
Victor

@VladislavAntonyuk VladislavAntonyuk added the not-reproduced Couldn't reproduce the bug label May 25, 2023
@gktval
Copy link
Author

gktval commented May 25, 2023

Thanks for testing and for responding.

I just updated to mac OS Ventura 13.4. updated to VS 17.5.6.
I am using Microsoft.MacCatalyst 16.4.7060, Maui 7.0.86, Xcode 14.3, NetCore 7.0.5, and .Net SDK 7.0.302

Still having the same error. A new Maui project works fine. It is only when CommunityToolkit that is referenced in MauiProgram.cs does the error occur.

@VladislavAntonyuk
Copy link
Collaborator

we plan a new release tomorrow. Let's see if it works to solve the issue.

@gktval
Copy link
Author

gktval commented May 26, 2023

Works now with 5.2. Thank you for updating the package.

@gktval gktval closed this as completed May 26, 2023
@marcojak
Copy link

marcojak commented Aug 27, 2024

I Still have this issue:

System.TypeLoadException: Could not set up parent class, due to: Invalid generic instantiation assembly:/...Microsoft.Maui.dll type:ViewHandler`2 member:(null)
at CommunityToolkit.Maui.AppBuilderExtensions.<>c.b__0_0(IMauiHandlersCollection h)

I'm using Rider.
CommunityToolkit.Maui Version="9.0.3"
and
Maui Version="8.0.80"

@showtroylove
Copy link

I Still have this issue:

System.TypeLoadException: Could not set up parent class, due to: Invalid generic instantiation assembly:/...Microsoft.Maui.dll type:ViewHandler`2 member:(null) at CommunityToolkit.Maui.AppBuilderExtensions.<>c.b__0_0(IMauiHandlersCollection h)

I'm using Rider. CommunityToolkit.Maui Version="9.0.3" and Maui Version="8.0.80"

Ditto! This bug has been reintroduced, it appears.

@showtroylove
Copy link

I Still have this issue:

System.TypeLoadException: Could not set up parent class, due to: Invalid generic instantiation assembly:/...Microsoft.Maui.dll type:ViewHandler`2 member:(null) at CommunityToolkit.Maui.AppBuilderExtensions.<>c.b__0_0(IMauiHandlersCollection h)

I'm using Rider. CommunityToolkit.Maui Version="9.0.3" and Maui Version="8.0.80"

I Still have this issue:

System.TypeLoadException: Could not set up parent class, due to: Invalid generic instantiation assembly:/...Microsoft.Maui.dll type:ViewHandler`2 member:(null) at CommunityToolkit.Maui.AppBuilderExtensions.<>c.b__0_0(IMauiHandlersCollection h)

I'm using Rider. CommunityToolkit.Maui Version="9.0.3" and Maui Version="8.0.80"

Perform a Clean Project or Solution and Rebuild corrected the issue for us. VS2022 on Mac .NET MAUI 8 CTK 9.0.2 (rollback, but will updated to see if issue reappears).

@AncientLust
Copy link

Had this issue after updating from CommunityToolkit.Maui 8.0.1 to 9.0.3. Solution was:

  • Update MAUI workloads via dotnet workload update
  • Restart the system (probably not necessary)
  • Drop bin and obj (Clean or Rebuild didn't work)

@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working not-reproduced Couldn't reproduce the bug unverified
Projects
None yet
Development

No branches or pull requests

7 participants