assembly.GetTypes 无法加载一个或多个请求的类型的解决方法

调用assembly.GetTypes报以下错误的解决方法

“System.Reflection.ReflectionTypeLoadException”类型的异常在 UnitTestBusiness2.dll 中发生,但未在用户代码中进行处理

其他信息: 无法加载一个或多个请求的类型。有关更多信息,请检索 LoaderExceptions 属性。

AppDomain代理调用的A.dll引用的B.dll没有找着,需设置以下应用程序目录名称

AppDomainSetup adSetup = new AppDomainSetup();
            adSetup.ApplicationBase = @"D:\Test\2017-4\MVCTest\UnitTestBusiness2\bin\Debug";

            AppDomain ad = AppDomain.CreateDomain("Assembly_Unload_AppDomain",null, adSetup);
            string appBase = ad.SetupInformation.ApplicationBase;


            ProxyObject proxy = (ProxyObject)ad.CreateInstanceFromAndUnwrap(System.Reflection.Assembly.GetExecutingAssembly().Location, typeof(ProxyObject).FullName);
            proxy.LoadAssembly(@"D:\Test\2017-4\MVCTest\UnitTestBusiness2\bin\Debug\Business1.dll");
            if (proxy.IsImplInterface(interfaceName))
            {
                string orderInfo = proxy.Invoke();
                Console.WriteLine(orderInfo);
            }
            proxy = null;
            AppDomain.Unload(ad);


这事情浪费了哥半天时间,记录一下!

你可能感兴趣的:(.net)