dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.57k stars 4.55k forks source link

MEF Attribute import isn't working in dotnetcore #27372

Open Petermarcu opened 5 years ago

Petermarcu commented 5 years ago

@maAfify commented on Thu Sep 06 2018

I have a dotnetcore dll 2.1 which is supposed to load another dotnetcore dlls plugins using MEF , i have in code :

ImportMany(typeof(PluginCreatorEnvironment))
catalog.Catalogs.Add(new DirectoryCatalog(dll plugin path))
var container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this);

I check the catalog , it loads in its loaded assemblies the right one , but importing doesn't happen to my this object.

I try same every thing with plugin in .net framework 4.6.1 , it is loaded and imported correctly , i have no compile error or even exception in debugger , just no imported attributes !

I use windows 10 , VS 2017 , .net core 2.1.3 .

Originally i am trying to migrate to all dotnetcore , but as i use MEF with many plugins , i face now these problems . I want to maintain using MEF using plugins loading , so i don't want to change the MEF code to directly refrence library.

levothanhhong commented 4 years ago

Same problem.