首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在MVC中为AppDomain加载文件或程序集。

无法在MVC中为AppDomain加载文件或程序集。
EN

Stack Overflow用户
提问于 2013-03-29 19:20:09
回答 1查看 368关注 0票数 1

我通过以下方式将程序集加载到应用程序域中:

代码语言:javascript
复制
            var appdomainSetup = new AppDomainSetup();
            //string appBase = Environment.CurrentDirectory;
            //string appBase = HttpContext.Current.Request.ApplicationPath;
            appdomainSetup.ApplicationBase = _appBase;//System.Web.HttpContext.Current.Request.ApplicationPath: Injected into cstor
            System.Diagnostics.Debug.WriteLine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
            appdomainSetup.DisallowBindingRedirects = false;
            appdomainSetup.DisallowCodeDownload = true;
            appdomainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            appDomain = AppDomain.CreateDomain("myAppdomain", null, appdomainSetup);

其中BLASSEMBLYLOCATION = "c:\path\myAssembly.dll";//for now just hard coded path

然后,我用另一种方法从这个程序集中获取一个类型:

代码语言:javascript
复制
var helperObject= appDomain.CreateInstanceAndUnwrap("myssembly.NameContinued", "myNamespace.BL.Helper") as Helper;//ERROR LINE HERE

在单元测试中,这一切都很好,很棒。但是,当在web应用程序中运行时,这会导致错误:

无法加载文件或程序集“myssembly.NameContinued”或其依赖项之一。

我可以在我的单元测试中通过不指定

appdomainSetup.ApplicationBase

我怀疑这个问题与我设置为ApplicationBase的目录有关。在web程序中,我传递HttpContext.Current.Request.ApplicationPath的值,我认为它是"/"

我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2013-03-29 19:35:23

我将ApplicationPath设置为放置程序集的路径:

代码语言:javascript
复制
appdomainSetup.ApplicationPath = @"c:\path";

因为这个程序集是由web项目引用的,所以我希望我的程序集与我的web项目包含在同一个目录中,这样我就可以使用相对路径(就像bin文件夹的工作一样)。然而,无论出于什么原因,这都是行不通的。到目前为止,在服务器上指定完整路径是唯一可行的解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15710038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档