7

Closed

APS.NET MVC3 RC2: Storage scopes cannot be created when _AppStart is executing.

description

I've experienced this bug in RC1 too ... I thought it would be solved but still getting this on RC2 ... so I thought reporting this before the RTM goes out.

Also reported by others here : http://forums.asp.net/p/1632696/4214831.aspx

This happens when the application is starting up after some changes to code and possibly after a re-compile happens ...
Please check this bug.
I can't replicate this because it happens in random moments ... but more frequently than you think.
Closed Nov 11, 2011 at 9:55 PM by
Closing this issue as we haven't been able to get a repro internally. Please reactivate if there is a reliable repro for us to look into. Thanks!

comments

jalchr wrote Jan 9, 2011 at 12:08 PM

I'm hosting the application on a RAM Disk which is very fast... I think this bug is due to miss-synchronization for the startup script. ... Please fix thanks

jalchr wrote Jan 20, 2011 at 3:40 PM

This is still happening in RTM

recalde wrote Jan 22, 2011 at 4:18 PM

This happens to be every time I launch my application to debug, does anyone know the underlying cause? Could it be that Controllers are instantiated by the framework before AppStart is complete?

CoolDadTx wrote Feb 2, 2011 at 7:08 PM

Definitely occurs in RTM version. Appears to happen if you do anything that will cause the app to have to be restarted. For example - debug the project to get it loaded, modify web.config, start debug again and you'll get it every time (at least for me). Seems like a sync issue.

drewmiller wrote Feb 2, 2011 at 7:27 PM

Thanks for the additional info, CoolDadTx; I'll use it to try to reproduce the issue and reply back. I'll create a work item internally and make sure the team looks at this for MVC 4, and also look to see if there are any work-arounds.

jorgebg wrote Feb 7, 2011 at 11:00 AM

I'm having this error also, only on development enviroment.

jfbosch wrote Feb 10, 2011 at 12:59 PM

I'm still getting this bug in the MVC3 release version.

cdmdotnet wrote Feb 22, 2011 at 9:37 PM

Having obtained the source and debugging symbols I can provide a stacktrace and easily replicate this issue on demand.... almost.
The issue finally occurs on line 31 of System.Web.WebPages.Scope.AspNetRequestScopeStorageProvider, which for those of you who don't have the source code is
    public IDictionary CurrentScope { 
        get {
            return PageScope ?? RequestScopeInternal ?? ApplicationScope; 
        } 
        set {
            if (!_appStartExecuted()) { 
                // Disallow creating new contexts before the start page is executed.
                // This makes sense because our provider is scoped to a request.
                throw new InvalidOperationException(WebPageResources.StateStorage_StorageScopesCannotBeCreated); // <========== HERE
            } 
            PageScope = value;
        } 
    } 
Unfortunately I cannot get all the variable values at this point because of compiled optimisations, but if anyone from MS would like to guide me through the stackstrace properly to save me looking in all the wrong places I'm more then happy to help.

jalchr wrote Feb 23, 2011 at 10:05 AM

I just can't believe what I see ... CurrentScope Property is not thread-safe ?????????????

recalde wrote Mar 21, 2011 at 7:04 PM

This continues to occur with MVC3 RTM, even with VS 2010 SP1. Is this going to be fixed? Has the defect been acknowledged by the ASP.NET team? Is this a problem with IE, Visual Studio, ASP.NET Development Server, or MVC 3 itself?

drewmiller wrote Mar 21, 2011 at 7:47 PM

We haven't been able to reproduce this issue within the test team, but yes, we believe it is likely a race condition in the Web Pages scope code. We've created an internal work item to investigate further and fix this issue, hopefully with the next release of the Web Pages runtime.

One question for those who've hit this issue: have you ever seen it in in a live app, or is it just when debugging and during development?

Many thanks to all for identifying this issue and for your investigation. If we identify a work-around, I'll update this page. And, of course, I'll update when we have a fix.

cdmdotnet wrote Mar 21, 2011 at 8:26 PM

I can confirm that this issue occurs only with debug code, but will occur with both the VS internal development web server and IIS7.5 (Win7) with and without a debugger attached.
In saying that I've not tried particularly hard to reproduce the issue with release code.

recalde wrote Mar 22, 2011 at 2:52 PM

Thanks Drew, I could not reproduce the issue with IIS Express, however it does occur using the WebDevServer on a brand new project (using the ASP.NET MVC 3 Web Application - Internet Application template).

vmrocha wrote Nov 1, 2011 at 5:12 PM

I'm having the same problem.

RanjiniM wrote Nov 1, 2011 at 7:24 PM

Hi vmrocha, could you provide the source of your _AppStart file and your controller? We have not been able to repro this issue internally yet.

vmrocha wrote Nov 1, 2011 at 8:23 PM

this is happening with all of my mvc applications. even with "file >> new project".

RanjiniM wrote Nov 1, 2011 at 9:59 PM

Hi vmrocha, can you please provide some more info? Are you using MVC3 or MVC4? IIS Express or WebDevServer?

saravanand wrote Mar 21, 2012 at 4:28 AM

I am also having this Issue after i migrated from MVC2 to MVC3. Any Fixes, please let me know.

shatl wrote May 1, 2012 at 1:25 PM

Just got it on latest ASP.NET MC3 version under WebDev server.

Stack: at System.Web.WebPages.Scope.AspNetRequestScopeStorageProvider.set_CurrentScope(IDictionary`2 value)
              at System.Web.WebPages.Scope.ScopeStorage.CreateTransientScope(IDictionary`2 context)
              at System.Web.WebPages.Scope.ScopeStorage.CreateTransientScope()
              at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
              at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
              at System.Web.Mvc.MvcHandler.c__DisplayClass6.c__DisplayClassb.b__5()
              at System.Web.Mvc.Async.AsyncResultWrapper.c__DisplayClass1.b__0()
              at System.Web.Mvc.Async.AsyncResultWrapper.c__DisplayClass8`1.b__7(IAsyncResult _)
              at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
              at System.Web.Mvc.MvcHandler.c__DisplayClasse.b__d()
              at System.Web.Mvc.SecurityUtil.b__0(Action f)
              at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
              at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
              at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
              at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
              at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)