HItesh Kumar
HItesh Kumar

Reputation: 119

Dyamically load platform specific dlls e.g. MicroSoft.Data.SqlClient is not supported on this platform

enter image description hereMicrosoft.Data.SqlClient is not supported on this platform

  1. Created a class library that is running SQL query using Microsoft.Data.SqlClient.
  2. Used DLL of that class library in console app (Including MIcrosoft.Data.SQLClient.dll)
  3. When running method of class library getting above error
  4. If referring MIcrosoft.Data.SQLClient.dll from runtimes\win\lib\net6.0 error got changed to (DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll)
  5. And if trying to add reference of Microsoft.Data.SqlClient.SNI.dll giving Bad IL format issue

Working Solution

  1. If switching AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true); Setting this at starting working fine but this is not recommended to use by Microsoft

  2. If referring MIcrosoft.Data.SQLClient.dll from runtimes\unix\lib\net6.0 it also works fine Don't know why but it doesn't seems good solution and can't use.

  3. If installing the Microsoft.Data.SqlClient in console app (Can't update existing Component handler)

Platform (VS 2022 and Win 10 .Net 6)

Upvotes: 0

Views: 159

Answers (1)

Chris F Carroll
Chris F Carroll

Reputation: 12370

You can't just “use” a dll, there's some work involved in loading the assembly, especially when it has platform-specific transitive dependencies.

This area of .Net is different under NetCore compared to NetFramework, so code that worked for NetFramework doesn't work for NetCore.

Upvotes: 2

Related Questions