DotNetCorePlugins icon indicating copy to clipboard operation
DotNetCorePlugins copied to clipboard

[Question] System.Data.SqlClient could not be found on my plugin

Open johmarjac opened this issue 1 year ago • 3 comments

Hello,

I have tried this library now with a simple plugin. All my projects reference net8.0-windows as I need WPF user controls in my plugins. But in not a single project i am in any way referencing System.Data.SqlClient, i am not using it... So why does it throw exception when trying to create a loder?

thanks

johmarjac avatar Dec 17 '23 10:12 johmarjac

Okay, I have tracked the issue down to where the problem comes from. In my Plugin contract I have a reference to System.Windows.Controls.TabItem like this:

public interface IPlugin
{
    string Name { get; }

    TabItem? TabItem { get; }
}

Plugin Implementation as simple as this:

public class Class1 : IPlugin
{
    public string Name => "TEST PLUGIN";

    public TabItem? TabItem { get; } = new TabItem()
    {
        Header = "NModbus",
        Content = new ContentControl()
    };
}

As soon as I have that TabItem reference in there, I get this error when trying to create a loader from that plugin:

image

Why is that?

Edit: When I add all those NuGet Packages:

<PackageReference Include="System.Data.Odbc" Version="8.0.0" />
<PackageReference Include="System.Data.OleDb" Version="8.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="System.Runtime.Serialization.Schema" Version="8.0.0" />
<PackageReference Include="System.ServiceModel.Syndication" Version="8.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0" />

then it works. but why is all those packages necessary? any idea?

johmarjac avatar Dec 19 '23 13:12 johmarjac

I am seeing the same issue. It's almost as if the Context Loader can't find the locally installed .NET framework. Did you happen to find any answer to this? @johmarjac

paschal77 avatar Aug 06 '24 19:08 paschal77

Frustrating, isn't it? ;---)

I found a quick workaround was to use this configuration option:

var loader = PluginLoader.CreateFromAssemblyFile(file, config => config.PreferSharedTypes = true); This has various implications which are explained - I could find the link tomorrow if you don't have it - but gets it working nicely!

HTH Jim

jgmdavies avatar Aug 06 '24 20:08 jgmdavies