CompliationLock throws HttpException when registering areas for ASP.NET MVC unit tests -


At the moment I have a unit test to test some of the area routing to my ASP.NET MVC application, I got HttpException System.Web.Complication.CompilationLock coming out as follows with stack trace Starter

  System.Web.HttpException :. Startup type for 'System.Web.Compilation.CompilationLock' threw an exception ---- & gt; System.TypeInitializationException: The beginning type for 'System.Web.Compilation.CompilationLock' threw an exception ---- & gt; System.NullReferenceException: The object reference is not set to an instance of an object. System.Web.Compilation.BuildManager.ReportTopLevelCompilationException () at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled () on System.Web.Compilation.BuildManager.GetReferencedAssemblies () at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc Bildmaniyr .Visual.FilterTypesInAssemblies (Aibiild manager system System.Web.Mvc.TypeCacheUtil.FilterTypesInAssemblies, Illuminant `1 predicate) on System.Web.Mvc.TypeCacheUtil.GetFilteredTypesFromAssemblies (string cache name, Predicate` 1 predicate, IBuildManager buildManager) system On. StpWeb.MvcApplication.RegisterRoutes (RouteCollection routes) in Global.asax.cs: on line StpWeb.Tests.RoutesTest.TestFixtureSetUp (in RoutesTest.cs) 16: line 11 --TypeInitializationException ompilationLock.GetLock System.Web.Compilation.BuildManager on System.Web.Compilation.C. EnsureTopLevelFilesCompiled () --NullReferenceException (reference boolean getLock) on System.Web.Compilation.CompilationLock..cctor ()  

Anyone else followed that MVC, if you ever For the addition of unit testing in the web application you create, you will get an issue.

This tells you to add a regional registration. The registrar connects all ARES () to the register roust method. Unfortunately, that is a stable method that bothers when the unit is called from the test.

Instead, Application_Start , register areas right RegisterRoutes before you call just modified if you RegisterRoutes before If you call, the UrlParameter.Optional area stops working in routes (though, continues to work in non-zone routes).

  Secure Zero Application_Start () {Area registration. Registrar All Ares (); RegisterRoutes (RouteTable.Routes); }  

Comments