Before you say anything, I have read the previously asked questions about this issue. The answers there did not fix my problem.
It’s pretty simple, I guess, if you know the answer. Here’s my problem:
I’ve got a solution with several projects, I’m creating a plugin-based application where I use Reflection to load all assemblies. This part goes fine, I load all my assemblies like so
var filePaths = Directory.GetFiles(@"C:\CustomerServiceModule\", "*.dll", SearchOption.AllDirectories).Where(n => n.Contains("bin"));
foreach (var f in filePaths)
{
Assembly.LoadFile(f);
}
Now I want to create an instance of a type, so I can work with it:
var assembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.ManifestModule.Name == "Kayako.dll").SingleOrDefault();
var name = assembly.GetTypes();
var type = assembly.GetType("Kayako.KayakoData");
var lol = Activator.CreateInstance(type);
This goes badly because inside KayakoData I have this:
KayakoService _service = new KayakoService("xxx", "yyy", "zzz");
This service is an assembly that works, I’ve used it before. Version number is fine, there’s nothing in the GAC that overrides it, I can’t see any errors using Assembly Binding Log Viewer. I still get this error:
[System.LoadTypeException]{“Could not load type ‘KayakoRestAPI.KayakoService’ from assembly ‘KayakoRestAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.”:”KayakoRestAPI.KayakoService”}
Anyone have any bright ideas? I’ve been staring myself blind at this. If I remove the service part from KayakoData the whole thing works, but I really need to run the service.
Quote from the documentation of the LoadFile method:
Conclusion: try LoadFrom in order to load dependent assemblies as well.