我正在使用反射加载两个程序集,然后使用它们中的一些类型。加载程序集后,加载一个类型,然后使用Activator实例化一个类型,当我尝试调用" LoadFromXml"时,我在程序集上得到一个FileNotFound异常。方法。这是以前的工作,我无法弄清楚改变了什么。此外,我可以从创建的实例获取属性没有问题。它只在调用方法" 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;
}
答案 0 :(得分:1)
经过一些调查后,似乎文件已经被另一个进程/程序集加载了。从Reflection.LoadFile()更改为Reflection.LoadFrom()可以解决问题。