刚刚成功加载程序集后找不到文件

File not found after I just successfully loaded assembly

我正在使用反射加载两个程序集,然后使用其中的一些类型。在加载程序集、加载类型然后使用 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;
    }

经过更多调查,该文件似乎已被另一个 process/assembly 加载。从 Reflection.LoadFile() 更改为 Reflection.LoadFrom() 可解决问题。