Storage scopes cannot be created when _AppStart is executing - asp.net-mvc-3

Using ASP.NET MVC 3.0 with Visual Studio 2010 (Pre-SP1 and with SP1) and ASP.NET Development server I get the error "Storage scopes cannot be created when _AppStart is executing." every time I debug. When I wait a couple seconds and refresh the browser it works as expected.
Does this happen to everyone?
Is there a way to prevent it?
Should I be concerned about this in production? (IIS 6/7 hosting)
Related work-item #7828 on codeplex has no official responses.
Full stack trace:
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

While I'm not sure why this happens (I also can't reproduce this) I might have some fixes that you might try. The WebPageHttpModule (in System.Web.WebPages) is supposed set AppStartExecuteCompleted but it doesn't, and that's why you get an exception (All this guess work is based on that).
So... Looking around the source code I BELIEVE that the source of this bug is something fishy with the Web Development Server and PreApplicationCode + dynamic registration of a module (WebPageHttpModule). The Module init should ALWAYS run at the application start, but for some reason I GUESS that it doesn't. Maybe someone can somehow test it.
Some fixes that I thought about (again, this is pure guess work as I can not reproduce this).
1) try to register the WebPageHttpModule module statically in the WebConfig. update I've tested this, and this doesn't throw an exception. However, it registers TWO httpmodules.
2) According to the comments on that thread you've linked it appears that this doesn't happen on IIS, so I would try to run under IIS Express (under VS 2010 SP1).
As I said before, this is just guess work. There could be other reasons for module not to run... Such as the Web Server not restarting properly, including some problem with the PreApplicationCode, or not resetting s_appStartExecutedLock to false in the HttpModule, or something wierd with the HttpContext.Items which could ALSO cause the module not to run...

This seems to still be a problem, certainly using the MVC 3 template on VS 2010 SP1. For anyone still having the problem, I found the solution on the following blog post to work quickly and reliably:
http://www.codinghub.net/2012/12/storage-scopes-cannot-be-created-when.html

I just had this happen for the first time on my project...and also can't reproduce. But I have a theory:
In a lapse of thinking, I had declared a static dictionary object within a helper class, and not too long after recompiling I got this error. This is my declaration:
private static Dictionary<string, string> FormatList = new Dictionary<string, string>();
Since static variables are shared across the entire web app (not just the context of the request), I'm thinking the constructor for the dictionary was getting triggered while App_Start was executing. This makes sense to me...since App_Start is probably setting up all of the session and application storage. If a static variable gets constructed before the storage is set up...boom goes the dynamite.
Just wanted to toss that theory out there...maybe it's the cause...maybe it's not. But it's something worth looking into (since statically declared objects like that are dangerous.)

Disconnect the Database. It cannot be re-created when a connection is active.
Thanks.

Simple rebuild solution helped me: please try to clean and rebuild (not sure "Microsoft" released MVC3 with any heavy bug)

Related

Web API 404 File or Directory not Found for "root" routes

I am developing a RESTful web api service. It's web api v.1, not v.2. Also I am developing on Visual Studio 2010 SP1. I have installed the MVC 4 for VS2010 SP1.
Please understand and keep in mind that Upgrading to newer versions of VS or Web Api 2 is not an option.
I have the following problem after a Windows Update ocurred.
When I try to use my RESTful api this way....
http://url.com/documents/ (get all the documents) I get the following error...
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Here is the stack trace.
[HttpException]: File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at system.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
If I specify the action name directly, it works. For example...
http://url.com/documents/get (gets all the documents) or
http://url.com/documents/7 (gets document id=7.
It only fails when you call it by its default name. I have already read similar situations here and I have tried to follow their solutions but they are not working for me properly.
Now, I know this is not a "web api routing" issue because I actually get the .net default exception page html markup (I am using Postman to test my webservice). When I force a "routing issue", then I get a JSON error description, which means that the Controller actually got created in the pipeline and returned a response.
Also, I have a custom file (SecurityHandler) that inherits from DelegatingHandler. This file gets executed almost first in the pipeline with each call to the api. Even before the actual Controller. Well, this file is never called when I get the error, which confirms to me that the "webserver" (either VS Development Server or IIS 7) is the one throwing the exception.
I have exhausted every single solution that I have found here. Change my web.config to multiple handlers configurations, re-installed MVC 4 for VS2010, created an entire new project... all these efforts have shown no results whatsoever.
Like I said, this was working perfectly fine until my pc restarted from a Windows Update BUT... why does it fail in the server as well? I did deploy my api to the server after the error started to occur.
Thanks.
The issue is not in Web API (and has nothing to do with it's version or Visual Studio 2010), it's the static file handler trying to serve and failing.
Alternatives:
0. Do you have a documents folder in your site? Get rid of it.
1. Remove the static file handler for directory browsing and re-add it.
2. Use RAMMFAR (less recommended)

Validation failed in Entity Framework, ASP.NET MVC3

My application using ASP.NET MVC3 with EF4.1, deployed on IIS7. Recently I've meet an error when trying to save an entity to an existing database on the production server, but everything goes well on my development machine.
I tried to build deploy package in VS2010 and import that package in IIS7, also, I've tried to upload all the solutions and create an application in IIS7 manually, but both of the 2 sites come to an error when executing a function that saves an entity to the database.
Error message is pasted below, but the physical path in error message does not exist in the production server, it's a path in my local development machine. This makes me confused. Has anybody ever seen this before?
BTW, I've fully backed up my database and restored it on the production server, so all the databases are same.
I'm open to hear any advice.
Thanks
Cheng
Error message:
Server Error in '/xxxx' Application. Validation failed for one or
more entities. See 'EntityValidationErrors' property for more details.
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.Data.Entity.Validation.DbEntityValidationException: Validation
failed for one or more entities. See 'EntityValidationErrors' property
for more details.
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:
[DbEntityValidationException: Validation failed for one or more entities. See
'EntityValidationErrors' property for more details.]
System.Data.Entity.DbContext.SaveChanges() +212
xxxxx.Models.SetupRepository.CreateApplicationOption(Guid companyId) in
D:\xxxx\Models\SetupRepository.cs:59
xxxxx.MvcApplication.MvcApplication_PostAcquireRequestState(Object sender, EventArgs e) > in D:\xxxx\Global.asax.cs:87
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +75

Umbraco installation problem. Can not install starter kit. The key was not present in the dictionary

This is a problem I get when trying to install Umbraco. I know that Umbraco has its own forum, but they have just moved it to another url, and I can not seem to be able to post a question there. So I try here. I know this problem has been reported before, and have tried to implement the solutions other people have reported. But I still can not seem to get it working. I have tried to both use Windows installer, as well as setting up the site myself. Last week I managed to create a site, and install a starter kit. But now I can not make it work. No idea why. I do the exact same steps as last week. I have .NET 4.0, IIS 7 and Windows 7. The Umbraco version is the latest (4.7).
No matter if I use Windows installer, or the binary-package from Codeplex, the installation process works fine until the step when I am presented the choice of installing a starter kit. I press for example the Business Startkit, but then I get the error below. I have given full permission for my application folder in inetpub, to IIS_IUSRS, Network service and Network. I have done the same for C:/Temp folder (as suggested by someone). I am using an app-pool that runs on .NET 4.0 in Integrated mode. I also set it to use Network service. I have also tried to both start off with a blank database, as well as creating a new one. The database gets populated with tables. The folder in inetpub is also filled with all the folders and files that should be there. I have also tried using SQL CE, but with out luck. And I do have a working internet connection.
Does anybody have any ideas on how to solve this? It's getting really frustrating. I think I have tried all the suggestions in the other threads, but I might have misunderstood something, missed some steps, or forgotten some advice. Any suggestions are highly appreciated.
The error I get:
Server Error in '/site_development' Application.
The given key was not present in the dictionary.
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.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
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:
[KeyNotFoundException: The given key was not present in the dictionary.]
System.Collections.Generic.Dictionary`2.get_Item(TKey key) +2258321
umbraco.cms.businesslogic.datatype.controls.Factory.GetNewObject(Guid DataEditorId) +108
umbraco.cms.businesslogic.datatype.DataTypeDefinition.Import(XmlNode xmlData) +459
umbraco.cms.businesslogic.packager.Installer.InstallBusinessLogic(Int32 packageId, String tempDir) +187
umbraco.presentation.install.steps.Skinning.loadStarterKits.SelectStarterKit(Object sender, EventArgs e) +416
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +113
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
Are you able to install Umbraco firstly without the starter kit?
If so it maybe an issue with the starter kit itself.
Or get the latest nightly build from Umbraco here http://nightly.umbraco.org/

.net framework data provider error

what is this error(comes up when i test my project)
-->
Unable to find the requested .Net Framework Data Provider. It may not be installed.
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.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
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:
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1402071
System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactory() +67
System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactorySecure() +22
System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +11
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +117
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
This is the Configuration
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="DataSource=C:\ProgramFiles\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\CIEDB.sdf;Password=sa;Persist Security Info=True"
providerName="Microsoft.SqlServerCe.Client.3.5" />
<add name="ConnectionString2" connectionString="Data Source=C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Samples\Northwind.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
You probably have to set up the correct configuration information (connection strings) in the test project's .config file
Edit: with that config, I did some searching and came across this forum thread:
http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/ff731bf4-1f50-4f77-955b-e4534474a271/
Where the apparent accepted answer was:
I fix my issue by manually install
SSCEVSTools-Enu.msi from Vs SP1.
There were a few other results on Bing that may be useful as well. Hope it helps
I had this same error when I installed Visual Studio 2010 SP1, then rolled back after I found out it was not so great (major understatement... stay far away from VS2010 SP1). I found online that I could fix this by reinstalling the and I got that file from here. After the reinstall of that software, i started VS 2010 and everything was back to normal. Hope it works for you.
Here is the link I used to get that package:
http://download.microsoft.com/download/0/5/D/05DCCDB5-57E0-4314-A016-874F228A8FAD/SSCEVSTools-ENU.msi
From your description, I assume the connection string is invalid. One easy way to create a working connection string is the following:
Create a new, empty text file on the desktop
Change its file extenstion to .udl
Double click on it. This opens the connection wizard.
Configure the connection. Then click on TEST. If the connection succeeds, close the wizard
Open the .udl file in a text editor. It contains a valid connection string.
Copy the connection string from the text editor into your Visual Studio data source string.

MS Unit Testing in VS 2010, Test Method [my method] threw an exception: ..., WT*?

I've got an ASP.NET MVC 2 Web app in VS 2010 and decided to try using MS unit testing stuff. What do you know, on the first test I created it gives me grief and refuses to elaborate.
I have created a single test class and a single test method. I am using Moq to create a HttpContext (including Request, Response, Session, QueryString, Form and Cookies). The method is testing an action on one of my controllers and an exception is occurring in that action when it use MVCs model binding capabilities. However that is not the problem.
When I run the test in VS it simply says: "Test Method [myTestMethodNameHere] threw exception: ..."! So it doesn't give me any idea what the exception is it literally says ... at the end, like a cliffhanger on TV - "... find out in VS 2011, coming soon" 8(.
Debugging the test doesn't help as it's occuring on the UpdateModel(T) line that I'm calling. I am using my own custom binder class but it doesn't get to the breakpoint on the first line of code in that so the exception must be happening in the MVC framework.
I guess this is all a long winded way of asking is there some configuration or code that needs to be written to get the MS unit testing framework to show me the exception in the test results window, is it me or does it sound like an MS issue that others have had?
Any help much appreciated,
Peter
Right click the failed test in the Test Results pane, and click View Test Result Details. You'll be given a document that specifies the exception, its message and stack trace.
Since you're using Moq, I'm guessing the type will be MoqVerificationException - MSTest unfortunately doesn't pick it up the same way it picks up AssertFailedExceptions, so no nice error messages there...

Resources