问题
I'm developing some WPF application which supports MEF plug-in features. It founds plugin by get exports from DirectoryCatalog, like
DirectoryCatalog catalog = new DirectoryCatalog(@".\libs", fileName);
CompositionContainer container = new CompositionContainer(catalog);
BaseModel.Instance.ImportedPlugins = container.GetExports<IExternalServiceProvider>();
So basically, I wanted this to load FILENAME.dll inside of the sub folder which named libs. However, when the dll file named FILENAME.dll exists both main folder and libs folder, that code loads FILENAME.dll of main folder.
Debug
ㄴlibs
ㄴFILENAME.dll(latest build) - This one should be loaded
ㄴApp.exe
ㄴFILENAME.dll(old build) - but this one is loaded instead
I tried several scenarios, but it makes me more confusing.
CASE 1
Debug
ㄴlibs
ㄴFILENAME.dll(latest version)
ㄴApp.exe
ㄴFILENAME.dll(old version)
-> old version is loaded
CASE 2
Debug
ㄴlibs
ㄴFILENAME.dll(latest version)
ㄴApp.exe
ㄴFILENAME.dlllll(old version)
-> latest version is loaded
CASE 3
Debug
ㄴlibs
ㄴFILENAME.dll(latest version)
ㄴApp.exe
ㄴWRONGFILENAME.dll(old version)
-> latest version is loaded
CASE 4 (Most confusing case)
Debug
ㄴlibs
ㄴWRONGFILENAME.dll or FILENAME.dlllll(latest version)
ㄴApp.exe
ㄴFILENAME.dll(old version)
-> failed to load any of them
I may try different way of using Catalog to solve this loading problem, but I can't find why and how Case 4 happens. What was I doing wrong?
来源:https://stackoverflow.com/questions/61587096/c-sharp-mef-directorycatalogs-unexpected-result-with-identical-dll-file-name