This project is read-only.

Default Entity Container name not found

Jul 21, 2010 at 2:05 PM


First of all, let me say thanks for the tutorial! As one who is brand new to C# and MVC, I've found it a great help.

Here's my problem. I have worked through the tutorial and am now stuck on Page 61/62 (Add validations). Let me say that everything worked fine until this point.

I added the Albums.cs as per the instructions. (And yes, everything is there and spelt properly!)

When I try to run the system now, I get the following error:

The specified default EntityContainer name 'mvcMusicStoreEntities' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName

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: The specified default EntityContainer name 'mvcMusicStoreEntities' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName

Source Error:

Line 41:         /// Initializes a new mvcMusicStoreEntities object using the connection string found in the 'mvcMusicStoreEntities' section of the application configuration file.
Line 42:         /// </summary>
Line 43:         public mvcMusicStoreEntities() : base("name=mvcMusicStoreEntities", "mvcMusicStoreEntities")
Line 44:         {
Line 45:             this.ContextOptions.LazyLoadingEnabled = true;

Source File: C:\Users\carol\documents\visual studio 2010\Projects\MvcMusicStore2\MvcMusicStore2\Models\StoreDB.Designer.cs    Line: 43 

Stack Trace:

[ArgumentException: The specified default EntityContainer name 'mvcMusicStoreEntities' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName]
   System.Data.Metadata.Edm.ClrPerspective.SetDefaultContainer(String defaultContainerName) +8510251
   System.Data.Objects.ObjectContext.set_DefaultContainerName(String value) +69
   System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +40
   MvcMusicStore2.Models.mvcMusicStoreEntities..ctor() in C:\Users\carol\documents\visual studio 2010\Projects\MvcMusicStore2\MvcMusicStore2\Models\StoreDB.Designer.cs:43
   MvcMusicStore2.Controllers.StoreController..ctor() in C:\Users\carol\documents\visual studio 2010\Projects\MvcMusicStore2\MvcMusicStore2\Controllers\StoreController.cs:15

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
   System.Activator.CreateInstance(Type type) +6
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +491

[InvalidOperationException: An error occurred when trying to create a controller of type 'MvcMusicStore2.Controllers.StoreController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +628
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +204
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +193
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +160
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +80
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +45
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8837208
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

I've tried everything I can think of, but to no avail.

Does anyone have any idea what is wrong? Is it possible that the problem is I have not yet added the ASPNETDB.MDF?

Thanks for any and all help!!!


Apr 15, 2011 at 1:09 AM


On the Solution Explorer, right click on the Entity Data Model file (.edmx) and click 'Open with'. A dialog box will open up to choose a program for you to open the file. Select or Double click on 'XML (text) Editor'. 
Now you re looking at the XML version of the EDM file where you can easily edit the 'EntityContainer' name. 
If you have changed the connectionstring on the webconfig file, make sure the 'DefaultContainerName' is the name on section 'EntityContainer' in that XML file.
Usually when you update the defaultContainerName in *.Designer.cs file, it doesn't update the XML file. So you have do it manually.