Microsoft.Data.SqlClient is not supported on this platform
- Created a class library that is running SQL query using Microsoft.Data.SqlClient.
- Used DLL of that class library in console app (Including MIcrosoft.Data.SQLClient.dll)
- When running method of class library getting above error
- If referring MIcrosoft.Data.SQLClient.dll from runtimeswinlibnet6.0
error got changed to (DllNotFoundException: Unable to load DLL ‘Microsoft.Data.SqlClient.SNI.dll) - And if trying to add reference of Microsoft.Data.SqlClient.SNI.dll giving Bad IL format issue
Working Solution
-
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
-
If referring MIcrosoft.Data.SQLClient.dll from runtimesunixlibnet6.0 it also works fine Don’t know why but it doesn’t seems good solution and can’t use.
-
If installing the Microsoft.Data.SqlClient in console app (Can’t update existing Component handler)
Platform (VS 2022 and Win 10 .Net 6)
13
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.
-
For .Net Framework, the discussion at Best Practices for Assembly Loading works.
-
For .Net Core, the discussion at Dependency Loading helps but a faster start might be working through Nate McMaster’s Plugin code