Cannot load assembly, but it's a lie
[goal]
I have a problem of DLL loading, and I have a fix. But I can't understand what's happening in the first place.
[context]
I am familiar with C#, C++/CLI( managed), Assemblies, .Net, .NetCore. I understand "strong names", public key.
I am also familiar with DLLs, delay loading, run-time assembly loading and reflection. I usually know how to handle dependencies at the project level or at run-time.
[a little more context]
I have a .Net 8.0 project with plenty of DLLs and dependencies, and only one of them is a problem.
This is DockPanelSuite 3.1.0 https://github.com/dockpanelsuite/dockpanelsuite
DockPanelSuite can flawlessly be upgraded and compiled for .net core 8.0 thanks to the ".Net Upgrade assistant"
DockPanelSuite contains (among others) :
- WeifenLuo.WinFormsUI.Docking.dll (the core)
- WeifenLuo.WinFormsUI.Docking.ThemeVS2005.dll (a theme), which depends (at the project level) on WeifenLuo.WinFormsUI.Docking.dll
My project contains a reference to both WeifenLuo.WinFormsUI.Docking DLLs.
[finally the problem]
In my code,
dockPanel = gcnew WeifenLuo::WinFormsUI::Docking::DockPanel()
works perfectly well
However, gcnew WeifenLuo::WinFormsUI::Docking::VS2005Theme()
will issue an exception (when calling the method containing the actual gcnew WeifenLuo::WinFormsUI::Docking::VS2005Theme()
)
System.IO.FileNotFoundException : 'Could not load file or assembly 'WeifenLuo.WinFormsUI.Docking.ThemeVS2005, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5cded1a1a0a7b481'. Le fichier spécifié est introuvable.'
Version, PubblicKeyToken are correct, there are no hidden dependencies, the assembly should load ! And I can actually load it and create the desired object :
System::String^ assemblyPath = System::Reflection::Assembly::GetCallingAssembly()->Location;
System::String^ folderPath = !assemblyPath ? nullptr : System::IO::Path::GetDirectoryName(assemblyPath);
System::String^ subassemblyPath = !folderPath ? nullptr : System::IO::Path::Combine(folderPath, "WeifenLuo.WinFormsUI.Docking.ThemeVS2005.dll");
System::Reflection::Assembly^ assembly = !subassemblyPath ? nullptr :
System::Reflection::Assembly::LoadFrom(subassemblyPath);
System::Type^ themeType = !assembly ? nullptr : assembly->GetType("WeifenLuo.WinFormsUI.Docking.VS2005Theme");
System::Object^ themeInstance = !themeType ? nullptr : System::Activator::CreateInstance(themeType);
I don't have a clue of what's happening. What could cause the load to fail in the first place ?