首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >执行_AppStart时无法创建存储作用域

执行_AppStart时无法创建存储作用域
EN

Stack Overflow用户
提问于 2011-03-22 03:52:52
回答 5查看 9.4K关注 0票数 19

使用带有Visual Studio2010(Pre-SP1and with SP1)的ASP.NET MVC3.0和ASP.NET开发服务器时,我每次调试时都会收到错误消息“存储作用域无法在_AppStart执行时创建。”。当我等待几秒钟并刷新浏览器时,它会按预期工作。

  • 这种情况会发生在每个人身上吗?
  • 有没有办法防止这种情况发生?
  • 在生产中是否应该关注这种情况?(IIS6/7主机)

Related work-item #7828 on codeplex没有官方回应。

完整堆栈跟踪:

代码语言:javascript
复制
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
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-03-22 06:24:11

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

所以..。浏览一下源代码,我认为这个bug的来源是Web Development Server和PreApplicationCode +动态注册模块(WebPageHttpModule)的可疑之处。Module init应该总是在应用程序启动时运行,但出于某种原因,我猜它不会运行。也许有人可以以某种方式测试它。

我想过的一些修复(再一次,这是纯粹的猜测,因为我不能重现)。

1)尝试在WebConfig中静态注册WebPageHttpModule模块。更新我已经测试过了,并没有抛出异常。但是,它注册了两个httpmodule。

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

正如我之前所说的,这只是一种猜测。可能还有其他原因导致模块无法运行...例如,Web服务器没有正确重新启动,包括PreApplicationCode的一些问题,或者在HttpModule中没有将s_appStartExecutedLock重置为false,或者HttpContext.Items出现了一些问题,这也可能导致模块无法运行……

票数 7
EN

Stack Overflow用户

发布于 2013-03-07 03:00:58

这似乎仍然是一个问题,当然是在VS2010 SP1上使用MVC3模板。对于任何仍然有这个问题的人,我在下面的博客文章中找到了快速可靠的解决方案:

http://www.codinghub.net/2012/12/storage-scopes-cannot-be-created-when.html

票数 3
EN

Stack Overflow用户

发布于 2012-02-01 07:27:12

我刚在我的project...and上第一次发生了这种情况,也不能重现。但我有一个理论:

由于一时疏忽,我在一个helper类中声明了一个静态字典对象,在重新编译后不久,我就得到了这个错误。这是我的声明:

代码语言:javascript
复制
private static Dictionary<string, string> FormatList = new Dictionary<string, string>();

由于静态变量是在整个web应用程序中共享的(而不仅仅是请求的上下文),所以我认为字典的构造函数是在App_Start执行时触发的。这对于me...since App_Start可能正在设置所有会话和应用程序存储是有意义的。如果在设置存储之前构造了一个静态变量,那么up...boom就会失败。

我只是想把这个理论抛在脑后,它是cause...maybe,它不是。但这是值得研究的(因为像这样静态声明的对象是危险的)。

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

https://stackoverflow.com/questions/5382856

复制
相关文章

相似问题

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