0
當我向ASP.NET MVC應用程序添加一個單元測試以測試某些區域路由時,我得到了一個來自System.Web.Complication.CompilationLock
類型初始值設定項的HttpException
以下堆棧跟蹤。CompliationLock在爲ASP.NET MVC單元測試註冊區域時拋出HttpException
System.Web.HttpException : The type initializer for 'System.Web.Compilation.CompilationLock' threw an exception.
----> System.TypeInitializationException : The type initializer for 'System.Web.Compilation.CompilationLock' threw an exception.
----> System.NullReferenceException : Object reference not set to an instance of an object.
at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
at System.Web.Compilation.BuildManager.GetReferencedAssemblies()
at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetReferencedAssemblies()
at System.Web.Mvc.TypeCacheUtil.FilterTypesInAssemblies(IBuildManager buildManager, Predicate`1 predicate)
at System.Web.Mvc.TypeCacheUtil.GetFilteredTypesFromAssemblies(String cacheName, Predicate`1 predicate, IBuildManager buildManager)
at System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state)
at System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state)
at System.Web.Mvc.AreaRegistration.RegisterAllAreas()
at StpWeb.MvcApplication.RegisterRoutes(RouteCollection routes) in Global.asax.cs: line 16
at StpWeb.Tests.RoutesTest.TestFixtureSetUp() in RoutesTest.cs: line 11
--TypeInitializationException
at System.Web.Compilation.CompilationLock.GetLock(ref Boolean gotLock)
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
--NullReferenceException
at System.Web.Compilation.CompilationLock..cctor()
我可以用同樣的問題在MVC的CodePlex網站已經保存了幾個小時,如果我發現[這個人](http://aspnet.codeplex.com/WorkItem/View.aspx?WorkItemId=4915) 。對該問題的評論提供了相同的解決方案。 – patridge 2010-05-17 18:36:24
當您創建一個空的MVC2項目時,這似乎是在VS2010中的Global.asax.cs中默認設置的。 – patridge 2010-09-19 03:18:46