I have the following situation: A few years ago I made a Universal Windows Project (to run on a Raspberry) and at the same time a WPF-project, using VisualStudio 2017 for both. The Raspberry writes on MySQL-database on a Win10 desktop, the WPF reads from this database and displays results. All worked fine.
Now I have to make a few changes. In the meantime I am using VisualStudio 2022. So I “migrated” both projects to VS 2022. The WPF functions like before, however the UWP gives me an error as soon as it tries to connect to the database. MySQL is uptodate.
This is the full error message:
System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlPoolManager' threw an exception. ---> System.TypeLoadException: Could not load type 'System.Runtime.Loader.AssemblyLoadContext' from assembly 'System.Runtime.Loader, Version=4.0.1.0, Culture=neutral
I searched the web, but did not find such an error message somewhere else and no hint that I could make use of. In case anybody has a clue – thanks so much in advance!
Something in the
MySqlPoolManagerstatic constructor is accessing a type that's not available on the platform you're running on.It's possible that using a different version of MySql.Data would help.
However, I would recommend switching to MySqlConnector (disclaimer: lead author) as an alternative C# ADO.NET library, as it has much better .NET Core support and fewer compatibility issues. (For example, see this question and answers where people report that it works better with Xamarin.) See the migrating from MySql.Data docs for more information.