locked
v1.0 BUG?: Unable to load the specified metadata resource. Scripts != Models RRS feed

  • Question

  • User-434868552 posted

    Server Error in '/' Application.  Unable to load the specified metadata resource.
    ArticleDBModel.Designer.cs    Line: 26
    Line 26:         public ArticleEntities() :
    Line 27:                 base("name=ArticleEntities", "ArticleEntities")

    After studying tutorial 1* and documenting** some comments about it,
    I finally began a non-trivial ASP.NET MVC applet.  Following the formula
    laid out in tutorial #1, I created a database, then a table, then a model,
    the a new controller, then proceeded to modify the Index view.  My
    expectations were high because of the ease and magic I experienced
    doing tutorial #1.  Unfortunately, when I clicked the "Articles" tab, I got:
        "Unable to load the specified metadata resource".

    I spent hours on Google, in forums,asp.net, stackoverflow, and msdn
    but nothing that I tried worked.  I examined every file in my solution
    and the Movies tutorial with WinDiff.  Finally, I printed both Web.config
    files and started highlighting the printouts.  Finally, I noticed:

    <add name="ArticleEntities" connectionString="metadata=res://*/Scripts.ArticleDBModel.csdl|res://*/Scripts.ArticleDBModel.ssdl|res://*/Scripts.ArticleDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>

     
    <add name="MoviesDBEntities"
    connectionString="metadata=res://*/Models.MoviesDBModel.csdl|res://*/Models.MoviesDBModel.ssdl|res://*/Models.MoviesDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MoviesDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>

    It appears that instead of generating "Models""Scripts" were generated.

    This is not code that I wrote, that's why I think it is likely a BUG in ASP.NET MVC v1.0 (RTM).

    The good news is that after changing Scripts to Models,
    my applet worked as expected.

    Regards,
    Gerry (Lowry)

      * http://www.asp.net/learn/mvc/tutorial-21-cs.aspx
        "Creating a Movie Database Application"
    ** http://forums.asp.net/t/1401522.aspx
       "Tutorial 1: c#, f.y.i.: errors in the first ASP.NET MVC tutorial ...
        Creating a Movie Database Application with ASP.NET MVC (C#)"
    Sunday, April 12, 2009 10:18 PM

Answers

  • User852981412 posted

    Hi Gerry,

    I have been able to generate the connection string that you had at first by highlighting the scripts folder and:

    Choosing 'add new item' , selecting 'ADO.Net Entity Data Model'

    Choosing a filename of 'ArticleDBModel.edmx'

    Choose generate from database, in the section that says save entity connection settings in the app.config as type 'ArticleEntities'

    Choose some db tables and select the model namespace as 'ArticleDBModel'

    It looks like you have then moved the .edmx file to the model folder, although when I do this from visual studio using drag-and-drop the connection string gets updated.

    Any chance you did that from outside of visual studio?

    Anyway I'm not sure that there is a bug here and if the connection string not getting updated for you is a bug it is most probably with the 'entity framework' tooling, not mvc.

    Maybe it's worth just trying tha above steps again then moving the edmx using drag-and-drop to see if it is taken care of for you?

    Hope that helps a bit,

    Paul

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 13, 2009 7:41 AM
  • User-434868552 posted
    Hi Paul, I appreciate your suggestions.

    I had to recreate my .edmx (see the thread http://forums.asp.net/t/1413536.aspx:
    "MVC or SQL problem? not sure? ?? MVC bug(s) ??").

    Therefore, based on your reply, above, I paid special attention.

    As with the movie database application, and as with my previous attempt,
    I carefully right-clicked the Models folder.  This time, instead of Scripts or Models,
    it chose Controllers:

    <add name="ArticleDBEntities" connectionString="metadata=res://*/Controllers.AriticleDBModel.csdl|res://*/Controllers.AriticleDBModel.ssdl|res://*/Controllers.AriticleDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />


    I blew that away again, and then it chose none of the above:

    <add name="ArticleEntities" connectionString="metadata=res://*/ArticleModel.csdl|res://*/ArticleModel.ssdl|res://*/ArticleModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

                                       Note, above:  ArticleModel has no prefix.
    Compare:
    <add name="ArticleEntities"
    connectionString="metadata=res://*/Models.ArticleDBModel.csdl|res://*/Models.ArticleDBModel.ssdl|res://*/Models.ArticleDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>

    Again, I got the error that follows my signature, below.

    Inserting Models. in front of ArticleModel resolved the error.

    Given the consistently inconsistent behaviour, after 40+ years as a programmer,
    to me this really looks like a BUG!

    Regards,
    Gerry (Lowry)

     

    Server Error in '/' Application.

    Unable to load the specified metadata resource.

    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.MetadataException: Unable to load the specified metadata resource.

    Source Error:

    Line 24:         /// Initializes a new ArticleEntities object using the connection string found in the 'ArticleEntities' section of the application configuration file.
    Line 25:         /// </summary>
    Line 26:         public ArticleEntities() : 
    Line 27:                 base("name=ArticleEntities", "ArticleEntities")
    Line 28:         {

    Source File: c:\!!!!!mne\mne\mne\models\articlemodel.designer.cs    Line: 26

    Stack Trace:

    [MetadataException: Unable to load the specified metadata resource.]
       System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +3542846
       System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +185
       System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +63
       System.Data.EntityClient.EntityConnection.SplitPaths(String paths) +659
       System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) +148
       System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() +26
       System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) +172
       System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +27
       mne.Models.ArticleEntities..ctor() in c:\!!!!!mne\mne\mne\models\articlemodel.designer.cs:26
       mne.Controllers.ArticleController..ctor() in C:\!!!!!mne\mne\mne\Controllers\ArticleController.cs:21
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
       System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
       System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) +82
    
    [InvalidOperationException: An error occurred while creating a controller of type 'mne.Controllers.ArticleController'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor.]
       System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) +189
       System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
       System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +128
       System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
       System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074 <!-- [MetadataException]: Unable to load the specified metadata resource. at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.EntityClient.EntityConnection.SplitPaths(String paths) at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) at mne.Models.ArticleEntities..ctor() in c:\!!!!!mne\mne\mne\models\articlemodel.designer.cs:line 26 at mne.Controllers.ArticleController..ctor() in C:\!!!!!mne\mne\mne\Controllers\ArticleController.cs:line 21 [TargetInvocationException]: Exception has been thrown by the target of an invocation. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) [InvalidOperationException]: An error occurred while creating a controller of type 'mne.Controllers.ArticleController'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 23, 2009 4:18 PM

All replies

  • User852981412 posted

    Hi Gerry,

    I have been able to generate the connection string that you had at first by highlighting the scripts folder and:

    Choosing 'add new item' , selecting 'ADO.Net Entity Data Model'

    Choosing a filename of 'ArticleDBModel.edmx'

    Choose generate from database, in the section that says save entity connection settings in the app.config as type 'ArticleEntities'

    Choose some db tables and select the model namespace as 'ArticleDBModel'

    It looks like you have then moved the .edmx file to the model folder, although when I do this from visual studio using drag-and-drop the connection string gets updated.

    Any chance you did that from outside of visual studio?

    Anyway I'm not sure that there is a bug here and if the connection string not getting updated for you is a bug it is most probably with the 'entity framework' tooling, not mvc.

    Maybe it's worth just trying tha above steps again then moving the edmx using drag-and-drop to see if it is taken care of for you?

    Hope that helps a bit,

    Paul

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 13, 2009 7:41 AM
  • User-434868552 posted
    Hi Paul, I appreciate your suggestions.

    I had to recreate my .edmx (see the thread http://forums.asp.net/t/1413536.aspx:
    "MVC or SQL problem? not sure? ?? MVC bug(s) ??").

    Therefore, based on your reply, above, I paid special attention.

    As with the movie database application, and as with my previous attempt,
    I carefully right-clicked the Models folder.  This time, instead of Scripts or Models,
    it chose Controllers:

    <add name="ArticleDBEntities" connectionString="metadata=res://*/Controllers.AriticleDBModel.csdl|res://*/Controllers.AriticleDBModel.ssdl|res://*/Controllers.AriticleDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />


    I blew that away again, and then it chose none of the above:

    <add name="ArticleEntities" connectionString="metadata=res://*/ArticleModel.csdl|res://*/ArticleModel.ssdl|res://*/ArticleModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

                                       Note, above:  ArticleModel has no prefix.
    Compare:
    <add name="ArticleEntities"
    connectionString="metadata=res://*/Models.ArticleDBModel.csdl|res://*/Models.ArticleDBModel.ssdl|res://*/Models.ArticleDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mne.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>

    Again, I got the error that follows my signature, below.

    Inserting Models. in front of ArticleModel resolved the error.

    Given the consistently inconsistent behaviour, after 40+ years as a programmer,
    to me this really looks like a BUG!

    Regards,
    Gerry (Lowry)

     

    Server Error in '/' Application.

    Unable to load the specified metadata resource.

    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.MetadataException: Unable to load the specified metadata resource.

    Source Error:

    Line 24:         /// Initializes a new ArticleEntities object using the connection string found in the 'ArticleEntities' section of the application configuration file.
    Line 25:         /// </summary>
    Line 26:         public ArticleEntities() : 
    Line 27:                 base("name=ArticleEntities", "ArticleEntities")
    Line 28:         {

    Source File: c:\!!!!!mne\mne\mne\models\articlemodel.designer.cs    Line: 26

    Stack Trace:

    [MetadataException: Unable to load the specified metadata resource.]
       System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +3542846
       System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +185
       System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +63
       System.Data.EntityClient.EntityConnection.SplitPaths(String paths) +659
       System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) +148
       System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() +26
       System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) +172
       System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +27
       mne.Models.ArticleEntities..ctor() in c:\!!!!!mne\mne\mne\models\articlemodel.designer.cs:26
       mne.Controllers.ArticleController..ctor() in C:\!!!!!mne\mne\mne\Controllers\ArticleController.cs:21
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
       System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
       System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) +82
    
    [InvalidOperationException: An error occurred while creating a controller of type 'mne.Controllers.ArticleController'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor.]
       System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) +189
       System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
       System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +128
       System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
       System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074 <!-- [MetadataException]: Unable to load the specified metadata resource. at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.EntityClient.EntityConnection.SplitPaths(String paths) at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) at mne.Models.ArticleEntities..ctor() in c:\!!!!!mne\mne\mne\models\articlemodel.designer.cs:line 26 at mne.Controllers.ArticleController..ctor() in C:\!!!!!mne\mne\mne\Controllers\ArticleController.cs:line 21 [TargetInvocationException]: Exception has been thrown by the target of an invocation. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) [InvalidOperationException]: An error occurred while creating a controller of type 'mne.Controllers.ArticleController'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 23, 2009 4:18 PM
  • User2020557925 posted

    I also came accross the same error but my problem was a different one.

    I am using a seperate Class Library for my data access which has the Entities in it. I have a reference in my Web Project to the data class library, and when I tried to run my web project I got the same error about :

    Unable to load the specified metadata resource


    I discovered I had forgot to copy the Connection string from my data access Class library into my web project's web config.

    Tuesday, September 29, 2009 9:59 AM