DotNetCorePlugins icon indicating copy to clipboard operation
DotNetCorePlugins copied to clipboard

Microsoft.Data.SqlClient is not supported on this platform

Open zraffaele opened this issue 2 years ago • 4 comments

Hi, in a method of plugin when create a connection i've this error. If i try to execute the same code in the hoster i don't encure in this error. Where is the my issue? Thank you.

zraffaele avatar Mar 07 '22 09:03 zraffaele

can you add some code? my first guess is maybe its your DI thats not configured correctly, but without code we wont know a thing.

aloksharma1 avatar Apr 07 '22 06:04 aloksharma1

I had the same problem. Have you solved it yet? @zraffaele

Victhy avatar May 30 '23 14:05 Victhy

While not using this project but the Microsoft article we solved it by keeping a list of platform-specific assemblies.

See the code at: https://gist.github.com/ramonsmits/aef6872d20192acd403fa883c923032a

var platformSpecificAssemblies = new Dictionary<string, string>
{
    ["Microsoft.Data.SqlClient"] = "net6.0",
    ["System.Data.SqlClient"] = "netcoreapp2.1"
};

var pluginLoadContext = new PluginLoadContext(pluginLocation, platformSpecificAssemblies);
var assemblyName = AssemblyName.GetAssemblyName(pluginLocation);
return pluginLoadContext.LoadFromAssemblyName(assemblyName);

Instead of passing a lookup dictionary, there is maybe a method to probe target specific folders in a certain order depending on the runtime but we didn't want to spend time on that as this makes it work for our requirement.

ramonsmits avatar Jun 08 '23 09:06 ramonsmits

After posting my last comment I just tested my last comment to probe for frameworks in a certain order and that works beautifully for our usage. I updated the gist.

ramonsmits avatar Jun 08 '23 10:06 ramonsmits