Tuesday, June 9

An MVC Bug: Unable to load the specified metadata resource

After I deleted the existing model and create a new one, the page shows:

Source File: C:\Data\src\Report.Web\Models\Model.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
Report.Web.Models.DataEntities1..ctor() in C:\Data\src\Report.Web\Models\Model.Designer.cs:26
Report.Web.Controllers.HomeController..ctor() in C:\Data\src\Report.Web\Controllers\HomeController.cs:20


and the error message is ambiguous, as always.

Thank god, gerrylowry helped me to identify the problem:

The web.config has a key
< name="DataEntities" connectionstring="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=" source="192.168.1.1;Initial" catalog="Data;Persist" info="True;User" id="id;Password="password;MultipleActiveResultSets="True" providername="System.Data.EntityClient">< /add>

and it should be:
< name="DataEntities" connectionstring="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.1.1;Initial Catalog=Data;Persist Security Info=True;User ID=id;Password=password;MultipleActiveResultSets=True"" providername="System.Data.EntityClient">< /add>