Maui: [BUG] iOS: System.TypeLoadException has been thrown with 9.0.3

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

Upgrading the CommunityToolkit.Maui package from 9.0.2 to 9.0.3 results in the app crashing at startup in iOS due to System.TypeLoadException has been thrown, Could not set up parent class, due to: Invalid generic instantiation assembly:...Microsoft.Maui.dll type:ViewHandler2 member:(null)`.

I have tried both with Maui 8.0.71 and 8.0.80.

One thing I noticed is that the dependencies of the NuGet have changed: 9.0.2 also required Microsoft.Maui.Controls.Compatibility >= 8.0.21 but 9.0.3 does not.

Expected Behavior

App not crashing, reverting back to 9.0.2 solves the issue.

Steps To Reproduce

Open a new project, install 9.0.3, run on iOS.

Link to public reproduction project repository

https://github.com/inimirpaz/maui_issues/tree/commtoolkit_ios_issue

Environment

- .NET MAUI CommunityToolkit: 9.0.3
- OS: MacOS
- .NET MAUI: 8.0.71 / 8.0.80

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 21 (4 by maintainers)

Most upvoted comments

I have the same issue. Working with Xcode 15.4 and Xcode 16 installed (command line tool set to 15.4) on MacOS Sonoma 14.6.1

On Windows side i have: CommunityToolkit.Maui 9.1.0 Maui 8.0.91 Maui sdk 8.0.4

result of workload list:

image

@filipnavara thank you for sharing this. It makes me happy to have a better understanding of what is happening. It sounds like we might need to opt into targeting specific versions like net8.0-ios17.0.

Cross-ref: https://github.com/xamarin/xamarin-macios/issues/21335

TL;DR: This is reoccurring issue due to the way the iOS Workload implicitly bumps the SDK version. If you have .NET 9 RC 1 SDK installed on a machine then CommunityToolkit.Maui 9.1.0 will not work unless you force using .NET 8 SDK with global.json and update all workloads to latest version.

I cannot reproduce this error using the provided reproduction sample.

I also cannot reproduce this error using CommunityToolkit.Maui.Sample.

This is likely a misconfiguration with your local environment.

@inimirpaz Please ensure you have installed the following items:

* [ ]  Xcode 15.4.0

* [ ]  Update to the latest stable version of Visual Studio (or Jet Brains Rider)

* [ ]  Download/install the [latest stable version of .NET 8 (v8.0.400)](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)

* [ ]  After installing .NET SDK v8.0.400, update to the latest stable version of .NET MAUI
  
  * On macOS, open the Terminal and enter the following command: `sudo dotnet workload install maui`
  * On Windows, open the command prompt (or Powershell) and enter the following command: `dotnet workload install maui`

Thanks @brminnick here’s where the problem lay… the .NET SDK was not updated to the latest stable version (it was 8.0.300-something). I have updated it to 8.0.400 and the problem is gone.

I cannot reproduce this error using the provided reproduction sample.

I also cannot reproduce this error using CommunityToolkit.Maui.Sample.

This is likely a misconfiguration with your local environment.

@inimirpaz Please ensure you have installed the following items:

  • Xcode 15.4.0
  • Update to the latest stable version of Visual Studio (or Jet Brains Rider)
  • Download/install the latest stable version of .NET 8 (v8.0.400)
  • After installing .NET SDK v8.0.400, update to the latest stable version of .NET MAUI
    • On macOS, open the Terminal and enter the following command: sudo dotnet workload install maui
    • On Windows, open the command prompt (or Powershell) and enter the following command: dotnet workload install maui