Reputation: 1525
I am loading two assemblies using reflection and then using a few types from them. After I load the assembly, load a type and then instantiate a type with Activator, I get a FileNotFound exception on the assembly when trying to invoke a "LoadFromXml" method. This was previously working and I cannot figure out what changed. Also, I can get a property from the created instance without a problem. It's only throwing exceptions when invoking the method "LoadFromXml."
private static object CheckForVersion(int version, string constructFilePath, string utilityFilePath)
{
if (!System.IO.File.Exists(constructFilePath) || !System.IO.File.Exists(utilityFilePath) || version < 7) return null;
var utilAssembly = System.Reflection.Assembly.LoadFile(utilityFilePath);
var constructAssembly = System.Reflection.Assembly.LoadFile(constructFilePath);
var InfoManager = utilAssembly.GetType(String.Format("{0}.InfoManager", utilAssembly.FullName.Split(',')[0]));
var ExecutionServerPropertiesConstructType = constructAssembly.GetType(String.Format("{0}.ExecutionServerPropertiesConstruct", constructAssembly.FullName.Split(',')[0]));
string dbFolder = (string)(InfoManager.GetProperty("ServerDatabaseFolder").GetValue(null, null));
if (Directory.Exists(dbFolder) == true)
{
string FilePath = Path.Combine(dbFolder, @"ExecutionServer.config.xml"); //DONT LOCALIZE
dynamic theServerProperties = Activator.CreateInstance(ExecutionServerPropertiesConstructType);
theServerProperties.LoadFromXml(FilePath);
var retVal = new
{
InstalledProductVersion = version,
ServerGuid = (string)InfoManager.GetField("SERVER_GUID").GetValue(null),
WorkflowRootnodeGuid = (string)InfoManager.GetField("WORKFLOW_ROOTNODE_GUID").GetValue(null),
TaskRootnodeGuid = (string)InfoManager.GetField("TASK_ROOTNODE_GUID").GetValue(null),
TriggerRootnodeGuid = (string)InfoManager.GetField("TRIGGER_ROOTNODE_GUID").GetValue(null),
ProcessRootnodeGuid = (string)InfoManager.GetField("PROCESS_ROOTNODE_GUID").GetValue(null),
ConnectionString = theServerProperties.ConnectionString
};
return Newtonsoft.Json.JsonConvert.SerializeObject(retVal);
}
return null;
}
Upvotes: 1
Views: 776
Reputation: 1525
After some more investigation, it seems like the file was already loaded by another process/assembly perhaps. Changing from Reflection.LoadFile() to Reflection.LoadFrom() resolves the issue.
Upvotes: 1