question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot load plugins with external dependencies in plugin interface

See original GitHub issue

I’m having trouble with loading plugin that contains an external dependency in the plugin interface. Let’s say that PluginBase project depends on System.Collections.Immutable package and my plugin interface looks as follows:

public interface ICommand
    {
        string Name { get; }
        string Description { get; }
        int Execute(ImmutableArray<string> input);
    }

When I try to load my plugin type I’m getting the following exeception:

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Method 'Execute' in type 'PluginArchitectureDemo.SamplePlugins' from assembly 'PluginArchitectureDemo.SamplePlugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Here is a repository with a solution that reproduces that problem https://github.com/cezarypiatek/PluginArchitectureDemo - just run PluginArchitectureDemo with a path to PluginArchitectureDemo.SamplePlugins.dll as the parameter.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vitek-karascommented, Dec 2, 2019

@cezarypiatek Could you please describe in more detail what is the exact failure you get after the suggested workaround?

I cloned your repo https://github.com/cezarypiatek/PluginArchitectureDemo and made one change in the PluginArchitectureDemo.SamplePlugins.csproj adding the <ExcludeAssets>runtime</ExcludeAssets> metadata to the project reference, like this:

  <ItemGroup>
    <ProjectReference Include="..\PluginArchitectureDemo.Contracts\PluginArchitectureDemo.Contracts.csproj">
      <Private>false</Private>
      <ExcludeAssets>runtime</ExcludeAssets>
    </ProjectReference>
  </ItemGroup>

Then I Rebuild the entire solution and the ran it - it works just fine for me.

0reactions
ljanicommented, Apr 30, 2021

Does this help with reproduction: https://github.com/ljani/dotnet-sdk-3814

I cleanup the sample a little bit and added some methods. Now it fails:

temp > git clone https://github.com/ljani/dotnet-sdk-3814.git
Cloning into 'dotnet-sdk-3814'...
remote: Enumerating objects: 45, done.
remote: Counting objects: 100% (45/45), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 45 (delta 17), reused 38 (delta 13), pack-reused 0
Receiving objects: 100% (45/45), 8.33 KiB | 2.08 MiB/s, done.
Resolving deltas: 100% (17/17), done.
temp > cd .\dotnet-sdk-3814\
dotnet-sdk-3814 > dotnet build
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored C:\temp\dotnet-sdk-3814\PluginBase\PluginBase.csproj (in 170 ms).
  Restored C:\temp\dotnet-sdk-3814\HelloPlugin\HelloPlugin.csproj (in 170 ms).
  Restored C:\temp\dotnet-sdk-3814\AppWithPlugin\AppWithPlugin.csproj (in 170 ms).
  PluginBase -> C:\temp\dotnet-sdk-3814\PluginBase\bin\Debug\net5\PluginBase.dll
  HelloPlugin -> C:\temp\dotnet-sdk-3814\HelloPlugin\bin\Debug\net5\HelloPlugin.dll
  AppWithPlugin -> C:\temp\dotnet-sdk-3814\AppWithPlugin\bin\Debug\net5\AppWithPlugin.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.33
dotnet-sdk-3814 > dotnet run --project AppWithPlugin
Loading commands from: C:\temp\dotnet-sdk-3814\HelloPlugin\bin\Debug\net5\HelloPlugin.dll
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method 'ConfigureServices' in type 'HelloPlugin.HelloCommand' from assembly 'HelloPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at AppWithPlugin.Program.CreateCommands(Assembly assembly)+MoveNext() in C:\temp\dotnet-sdk-3814\AppWithPlugin\Program.cs:line 84
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at AppWithPlugin.Program.Main(String[] args) in C:\temp\dotnet-sdk-3814\AppWithPlugin\Program.cs:line 27
System.TypeLoadException: Method 'ConfigureServices' in type 'HelloPlugin.HelloCommand' from assembly 'HelloPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

I thought it was because System.CommandLine.Hosting tries to pull v3.1.5 libs, but adding <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" /> did not help. I did not have time to investigate this further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve a dependency in an Eclipse plug-in I didn' ...
I tried importing the plugin as a source project, but the src/ directory is empty. The plugin doesn't appear in the list of...
Read more >
Create a .NET Core application with plugins
The tutorial correctly isolates the plugin's dependencies from the hosting application. You'll learn how to: Structure a project to support ...
Read more >
Difficulty Sharing Code Between Swift Package Manager ...
I'm currently writing an SPM package to house several utility plugins for a codebase, and these plugins overlap in functionality.
Read more >
Dependent Assembly plug-ins (preview) - Power Apps
If any signed assemblies depend on unsigned assemblies, you will get an error like the following: Could not load file or assembly '<AssemblyName> ......
Read more >
Feature Project: Plugin Dependencies – Make WordPress Core
Any plugin that requires another plugin (i.e., a dependency) is on its own to make sure admins install the dependency. After all, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found