-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IsAssignableFrom not working #44222
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
The issue is that --- a/HelloPlugin/HelloPlugin.csproj
+++ b/HelloPlugin/HelloPlugin.csproj
<ItemGroup>
- <ProjectReference Include="..\PluginBase\PluginBase.csproj" />
+ <ProjectReference Include="..\PluginBase\PluginBase.csproj" Private="false" ExcludeAssets="runtime" />
</ItemGroup> |
Tagging subscribers to this area: @vitek-karas, @agocke |
@am11 that does not work for me no matter what I try I have tried your suggestion but also the docs suggestion: <ItemGroup>
<ProjectReference Include="..\PluginBase\PluginBase.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup> |
It needs clean folder: delete all |
Yes I have done all that multiple times; I have manually deleted all the bin/obj folders |
My steps on Windows 10 are:
outputs:
which is different than what it produces without the
|
That looks like it hasnt worked; it should have output the commands available in the PlugIn and not |
So we can't blame IsAssignableFrom API for this? foreach( Type type in assembly.GetTypes() )
{
if( typeof( ICommand ).IsAssignableFrom( type ) )
{
var result = Activator.CreateInstance( type ) as ICommand;
if( result != null )
{
count++;
yield return result;
}
}
}
if( count == 0 )
{
string availableTypes = string.Join( ",", assembly.GetTypes().Select( t => t.FullName ) );
throw new ApplicationException(
$"Can't find any type which implements ICommand in {assembly} from {assembly.Location}.\n" +
$"Available types: {availableTypes}" );
} IsAssignableFrom seems to be working as expected. |
I delete the whole project and re-downloaded, applied your patch and then ran it through VS 2019 Preview and it worked:
Feels a bit flakey, but thanks ... now to try and get this working in my actual project |
The code is written in a way that it looks for command in first argument, we need to publish it first, as opposed to running with $ \temp\dotnet5\dotnet publish
$ \temp\dotnet5\dotnet bin\Debug\net5.0\PluginsTest.dll hello
Loading commands from: C:\Temp\PluginsTest\HelloPlugin\bin\Debug\net5.0\HelloPlugin.dll
-- hello --
Hello !!! |
|
I think this can be closed now; thanks for everyones input and help. |
Description
Following the steps to create a plugin architecture as shown in the MS Docs and is failing to compare the implemented interface from the loaded assembly using:
Whereas this works (as you would expect):
So does this:
Please see attached solution for example:
PluginsTest.zip
Configuration
Dotnet: .net 5.0.100-rc.2.20479.15
OS: Windows 10 Pro
Configuration: Any CPU (running on x64 laptop)
Regression?
This doesn't seem to work with .netcore3.1 or 3.0 either in either Visual Studio 2019 or 2019 Preview 6
The text was updated successfully, but these errors were encountered: