Strange exceptions when attempting to run referenced .NET Framework MySql Connector code from ASP.NET Core app

0

I have a solution with two projects. One targets .net framework 7, and contains a class that handles all the communication with a mysql database using the MySql.Data 8.0.17 driver/nugget. The other project targets .net core mvc 3 and references the latter project. Upon instantiating the db class from within the asp core project, and attempting to run a query from a call MySqlHelper.ExecuteNonQuery, I am receiving the following exception:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(String groupName)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText, MySqlParameter[] commandParameters)
   at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText)
   ...
Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Although I am not sure what that exception means, after some googling, I added the ConfigurationManager nugget which seemed to have resolved the issue, but now receive this exception:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'MySql.Data.MySqlClient.MySqlConnectAttrs' threw an exception.
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText, MySqlParameter[] commandParameters)
   at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText)
   ...
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Googling this exception suggested installing some sort of Windows Management Framework, but none of the downloadables are for Windows 10. At this point I am not sure what to do.

What/why is this happening? How do I fix it?

c#
mysql
asked on Stack Overflow Sep 29, 2019 by cubesnyc

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0