执行_AppStart时无法创建存储范围

rec*_*lde 19 asp.net-mvc-3

使用ASP.NET MVC 3.0与Visual Studio 2010(SP1之前和SP1)和ASP.NET开发服务器我每次调试时都会收到错误" 当_AppStart正在执行时无法创建存储范围. " 当我等待几秒钟并刷新浏览器时,它按预期工作.

  • 这会发生在每个人身上吗?
  • 有没有办法防止它?
  • 在生产中我应该关注这个吗?(IIS 6/7主机)

codeplex上的相关工作项目#7828没有官方回复.

完整堆栈跟踪:

Server Error in '/' Application.
--------------------------------------------------------------------------------
Storage scopes cannot be created when _AppStart is executing. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Storage scopes cannot be created when _AppStart is executing.

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: 
[InvalidOperationException: Storage scopes cannot be created when _AppStart is executing.]
   System.Web.WebPages.Scope.AspNetRequestScopeStorageProvider.set_CurrentScope(IDictionary`2 value) +83361
   System.Web.WebPages.Scope.ScopeStorage.CreateTransientScope(IDictionary`2 context) +95
   System.Web.WebPages.Scope.ScopeStorage.CreateTransientScope() +76
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +84
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Run Code Online (Sandbox Code Playgroud)

Lin*_*ron 7

虽然我不确定为什么会发生这种情况(我也无法重现),但我可能会尝试一些修复方法.WebPageHttpModule(在System.Web.WebPages中)假定设置为AppStartExecuteCompleted但它没有,这就是为什么你得到一个异常(所有这些猜测工作都基于此).

所以...环顾源代码我相信这个bug的来源是Web Development Server和PreApplicationCode +模块的动态注册(WebPageHttpModule).模块初始化应在应用程序启动始终运行,但由于某些原因,我GUESS,它没有.也许有人可以以某种方式测试它.

我想到的一些修复(再次,这是纯粹的猜测工作,因为我无法重现这一点).

1)尝试在WebConfig中静态注册WebPageHttpModule模块.更新我已经测试了这个,这不会引发异常.但是,它注册了两个httpmodules.

2)根据你所链接的那个帖子的评论,似乎这不会发生在IIS上,所以我会尝试在IIS Express下运行(在VS 2010 SP1下).

正如我之前所说,这只是猜测工作.模块无法运行可能还有其他原因...例如Web服务器无法正常重启,包括PreApplicationCode的某些问题,或者在HttpModule中没有将s_appStartExecutedLock重置为false,或者HttpContext.Items可能还有什么问题导致模块无法运行...