如何从filepath加载新的appdomain?

时间:2012-06-05 13:43:39

标签: c# asp.net .net reflection

对不起,加载dll太经典了。但我无法解决这个基本问题:我有一个插件文件路径我想将这些程序集加载到新域但我不能这样做。首先;它是一个Web应用程序,我的代码如下:感谢您的帮助:



     foreach (var filePath in arryFiles)
                {
                    Assembly asm = Assembly.LoadFile(filePath.ToString());
                    AppDomainSetup domainSetup = new AppDomainSetup();
                    domainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
                    domainSetup.DisallowBindingRedirects = false;
                    domainSetup.DisallowCodeDownload = true;
                    domainSetup.LoaderOptimization = LoaderOptimization.SingleDomain;
                    domainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                    ApplicationHost = AppDomain.CreateDomain("Ops.Mgr.Service", null, domainSetup);
                    // how to load into domain my assembly...

                }

谢谢你的帮助......

1 个答案:

答案 0 :(得分:2)

是否要将程序集加载到同一App Domain或不同的App Domain? 以下是在不同App Domain中加载程序集的解决方案:Loading DLLs into a separate AppDomain

在同一App Domain中加载程序集:Can I load a .NET assembly at runtime and instantiate a type knowing only the name?