无法加载指定的元数据资料Unable to load the specified metadata resource
2012-10-15 16:38
405 查看
在应用ADO.NET Entity Framework构建Application时呈现如下异常。Solution 中有2个项目,一个为Windows Form项目,另一个为Class Library 项目,包含ADO.NET Entity Data Model。Windows Form 项目增长对Class Library 项目标引用。 异常信息: System.Data.MetadataException was unhandled Message="Unable to load the specified metadata resource." Source="System.Data.Entity" StackTrace: 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.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() 在Windows Form 项目中呈现异常的代码: [align=left] string customerID = txtCustomerID.Text.Trim();[/align] [align=left] // Contains a reference to an Entity Data Model (EDM) and a data source connection.[/align] [align=left] using (EntityConnection cn = new EntityConnection("Name=NorthwindEntities"))[/align] [align=left] {[/align] [align=left] cn.Open();[/align] [align=left] EntityCommand cmd = cn.CreateCommand();[/align] [align=left] cmd.CommandText = [/align] [align=left] "SELECT VALUE c FROM NorthwindEntities.Customers "+[/align] [align=left] "AS c WHERE c.CustomerID = @customerID";[/align] [align=left] cmd.Parameters.AddWithValue("customerID", customerID);[/align] [align=left] DbDataReader rdr = cmd.uteReader(CommandBehavior.SequentialAccess);[/align] [align=left] while (rdr.Read())[/align] [align=left] Console.WriteLine(rdr["CompanyName"].ToString());[/align] [align=left] rdr.Close();[/align] } 上述代码行 cn.Open(); 抛出异常Exception - Unable to load the specified metadata resource。经搜检,题目呈如今App.config 设备文件(该设备文件在应用ADO.NET Entity Data Model领导时主动添加), ADO.NET Entity Data Model领导主动添加的Connection String: [align=left]<configuration>[/align] [align=left]<connectionStrings>[/align] [align=left] <add name="NorthwindEntities" connectionString="metadata=res://*/NorthwindDB.csdl|res://*/NorthwindDB.ssdl|res://*/NorthwindDB.msl; provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True""providerName="System.Data.EntityClient" />[/align] [align=left]</connectionStrings>[/align] </configuration> 须要将上方connectionStrings 设备节中的* 批改为Class Library 项目标Assembly Name。批改后的示例App.config 如下: [align=left]<configuration>[/align] [align=left]<connectionStrings>[/align] [align=left] <add name="NorthwindEntities" connectionString=" metadata= res://NorthwindEDM/NorthwindModel.csdl|res://NorthwindEDM/NorthwindModel.ssdl|res://NorthwindEDM/NorthwindModel.msl; provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True""providerName="System.Data.EntityClient" />[/align] [align=left]</connectionStrings>[/align] </configuration The problem sometimes occurs with the Entity Framework where it gives an array of errors when doing simple operations. For example, I received an error about not being able to &#8220;unable to load the specified metadata resource&#8221;. Uh, the connection string information is right in the config file! The problem often can be resolved simply by: open the EDMX file in the designer mode
go to the properties of the EDMX
set the Metadata Artifact Processing property to &#8220;Copy to Output&#8221;
build the project
然后从输出目次将*.msl.*.ssdl,*.csdl文件拷贝到应用法度目次底下即可。呵呵(估计很多人这里失足!)
go to the properties of the EDMX
set the Metadata Artifact Processing property to &#8220;Copy to Output&#8221;
build the project
然后从输出目次将*.msl.*.ssdl,*.csdl文件拷贝到应用法度目次底下即可。呵呵(估计很多人这里失足!)
相关文章推荐
- 无法加载指定的元数据资源Unable to load the specified metadata resource
- Entity Framework出现System.Data.MetadataException: Unable to load the specified metadata resource的解决方法
- ADO.NET Entity Framework “Unable to load the specified metadata resource”解决方法
- ADO.NET实体框架连接串引发的异常:Unable to load the specified metadata resource
- 使用Entity Framework遇到MetadataException: Unable to load the specified metadata resource
- ADO.NET实体框架连接串引发的异常:Unable to load the specified metadata resource
- Unable to load the specified metadata resource
- ADO.NET实体框架连接串引发的异常:Unable to load the specified metadata resource
- 【转】Unable to load embedded resource from assembly 无法加载的程序集嵌入的资源
- Unable to load workflow actions from the server(无法从服务器加载工作流操作)
- 错误:System.Data.MetadataException: 无法加载指定的元数据资源。
- hadoop无法加载本地库文件的原因 Unable to load native-hadoop library for your platform
- 错误:System.Data.MetadataException: 无法加载指定的元数据资源。
- C#开发的GDAL程序部署遇到的问题 (无法加载 DLL“gdal_wrap” Unable to load DLL 'gdal_wrap')
- mysql 找不到或无法加载已注册的 .Net Framework Data Provider和Unable to find the requested .Net Framework Data Provider. It may not be installed解决
- monogame Unable to load DLL 'openal32.dll': The specified module could not be found
- Android unable to load section nand_dev 它超过设备的限制,则无法加载部分nand_dev
- 无法加载php_exifUnable to load dynamic library 'D:/AppServ\php5\ext\php_exif.dll'
- Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- unable to load the requested database interface的解决方法