首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部署时未加载RazorGenerator.Mvc.dll

部署时未加载RazorGenerator.Mvc.dll
EN

Stack Overflow用户
提问于 2012-10-19 02:23:43
回答 1查看 4.4K关注 0票数 5

使用mvc.razor生成器让一切工作正常。我的库项目的视图在我的网站上显示得很好。它是一个.net 4.0,MVC4,EF5项目。应用程序池在IIS4.0中设置为.net 4.0。

当我部署到服务器时,当它试图加载PrecompiledMvcEngine类型时,我得到了一个异常。下面是一个例外(我在附件中附上了完整的error输出):

代码语言:javascript
复制
Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.Assembly.GetTypes() +159
RazorGenerator.Mvc.PrecompiledMvcEngine..ctor(Assembly assembly, String baseVirtualPath) +1209
RazorGenerator.Mvc.PrecompiledMvcEngine..ctor(Assembly assembly) +53
MyProj.Common.App_Start.RazorGeneratorMvcStart.Start() in E:\UserFiles\sheam\Documents\Visual Studio 2010\Projects\MyProj\Project.Common_vs2010\App_Start\RazorGeneratorMvcStart.cs:11

正如你所看到的,这来自于我的公共项目。

以下是bin目录的内容:

代码语言:javascript
复制
2012-10-17 09:06 PM <DIR> .
2012-10-17 09:06 PM <DIR> ..
2012-10-10 12:51 AM 105,528 Antlr3.Runtime.dll
2012-10-09 07:05 PM 1,118,296 EntityFramework.dll
2012-10-16 01:26 PM 359,424 MyProj.Common_vs2010.dll
2012-10-16 01:26 PM 112,128 MyProj.Common_vs2010.pdb
2012-10-09 06:46 PM 45,416 Microsoft.Web.Infrastructure.dll
2012-10-17 09:06 PM 29,696 MyProj.dll
2012-10-17 09:06 PM 42,496 MyProj.pdb
2012-10-13 08:04 PM 15,872 Mvc.Mailer.dll
2012-10-09 06:46 PM 374,784 Newtonsoft.Json.dll
2012-10-09 06:56 PM 15,872 RazorGenerator.Mvc.dll
2012-10-09 06:46 PM 180,832 System.Net.Http.dll
2012-10-09 06:46 PM 168,544 System.Net.Http.Formatting.dll
2012-10-09 06:46 PM 16,480 System.Net.Http.WebRequest.dll
2012-10-09 06:46 PM 138,328 System.Web.Helpers.dll
2012-10-09 06:46 PM 323,168 System.Web.Http.dll
2012-10-09 06:46 PM 73,312 System.Web.Http.WebHost.dll
2012-10-09 06:46 PM 506,976 System.Web.Mvc.dll
2012-10-10 12:51 AM 54,912 System.Web.Optimization.dll
2012-10-09 06:46 PM 264,792 System.Web.Razor.dll
2012-10-09 06:46 PM 41,048 System.Web.WebPages.Deployment.dll
2012-10-09 06:46 PM 204,376 System.Web.WebPages.dll
2012-10-09 06:46 PM 39,512 System.Web.WebPages.Razor.dll
2012-10-09 06:56 PM 8,704 WebActivator.dll
2012-10-10 12:51 AM 963,640 WebGrease.dll
24 File(s) 5,204,136 bytes
2 Dir(s) 1,519,661,289,472 bytes free

RazorGenerator.Mvc.dll存在于其中,所以我不确定为什么它不能加载该类型。

服务器是全新安装的,如果是W7专业版。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-21 02:34:03

事实证明,问题并不是剃须刀生成器。问题是RG通过反射加载的类缺少正确的程序集。这是两个Webmatrix的组合。

事实证明,即使设置了copy local (在库项目中),如果它存在于构建机器的GAC中,Visual Studio2010和2012实际上也不会复制它。在我示例中,构建机器安装了程序集(通过MVC3),但web服务器没有。我最终将这些程序集添加到我的web项目(而不是库)中,并将它们复制到本地。

这是一个令人讨厌的bug。我构建了一个特殊的异常处理程序,如果它再次发生,它会迅速指出这个问题。我的RazorGeneratorMvcStart中的Start()函数现在如下所示:

代码语言:javascript
复制
public static void Start() 
{
    PrecompiledMvcEngine engine = null;
    try
    {
        engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly)
        {
            UsePhysicalViewsIfNewer = HttpContext.Current.Request.IsLocal
        };
    }
    catch (System.Reflection.ReflectionTypeLoadException e)
    {
        StringBuilder exceptions = new StringBuilder("The following DLL load exceptions occurred:");
        foreach (var x in e.LoaderExceptions)
          exceptions.AppendFormat("{0},\n\n", x.Message);
        throw new Exception(string.Format("Error loading Razor Generator Stuff:\n{0}",exceptions));
    }

    ViewEngines.Engines.Insert(0, engine as PrecompiledMvcEngine);

    // StartPage lookups are done by WebPages. 
    VirtualPathFactoryManager.RegisterVirtualPathFactory(engine as PrecompiledMvcEngine);
}

不是很好,但我会弄清楚如何让它看起来更好,并在以后可重用。:)

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

https://stackoverflow.com/questions/12961224

复制
相关文章

相似问题

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