RazorGenerator.Mvc.dll does not load during deployment

everything works fine with the mvc.razor generator. Views from my library project show up on my website. This is a .net 4.0, MVC4, EF5 project. The application pool is installed in .net 4.0 in IIS.

When I deploy the server, I get an exception when it tries to load the PrecompiledMvcEngine type. Here is the exception (I attached the full error output in the attachments):

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 

As you can see, this comes from my overall project.

Here is the contents of the bin director:

 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 exists there, so I'm not sure why it cannot load the type.

Server is a new version if W7 Pro.

+4
source share
1 answer

It turns out that in fact it was not a razor generator. The problem was that the class that RG was loading through reflection was not in the correct assembly. These were two Webmatrix assmebly's.

It turns out that even if the copy locale is set (in the library project), Visual Studio 2010 and 2012 will not actually copy it if it exists in the assembly GAC machine. In my machine, to build the assembly, this assembly was installed (by MVC3), but the web server did not. I ended up adding these assemblies to my web project (and not to the library) and installing them there locally.

This is an unpleasant mistake. I am creating a special exception handler that quickly fixes this problem if it happens again. The Start () function in my RazorGeneratorMvcStart is as follows:

 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); } 

Not bad, but I’ll understand how to make it more enjoyable and reuse it later. :)

+8
source

Source: https://habr.com/ru/post/1440623/


All Articles