I am dynamically loading assemblies from a database table of assembly names, which insert rules into a rules engine. The idea is we can extend functionality by developing new rules without having to recompile and deploy the whole suite.
There's a MVC web application, and a WCF desktop application that share a great deal of the code, including the RulesRunner class I'm describing here.
This code is in the constructor of the RulesRunner class
rules = rulesEngineRepository.GetRules(x => x.Enabled);
foreach (var rule in rules)
{
var ruleAssembly = Assembly.LoadFrom($"{rule.AssemblyName}.dll");
var installerType = ruleAssembly.GetType("RulesEngine.Rules.RulesInstaller");
var installer = Activator.CreateInstance(installerType) as IWindsorInstaller;
container.Install(installer);
}
The RulesRunner class is not dynamically loaded, it's compiled in as a normal reference in both MVC and WCF code.
In the WCF case, this all works exactly as intended. The assembly is loaded, an instance is created and when the rules engine fires elsewhere it uses the rules loaded in this way perfectly.
In the MVC web application, this code returns a null from the Activator.CreateInstance line and so fails further along when it's called. I cannot for the life of me work out what's going on differently here.
If I inspect the variables after the call to container.Install(installer) I can see the variable installer reports "'installer' threw an exception of type 'System.IO.FileNotFoundException'".
But but but but... the installerType has all the correct information and value. It's like it's found the DLL to execute the LoadFrom, but then can't find it again when it tries to instantiate it two lines of code further along.
Aucun commentaire:
Enregistrer un commentaire