实体框架 - 无法加载指定的元数据资源

Ste*_*ead 32 c# entity-framework entity-framework-6

我意识到这已被问了很多次,但我似乎无法解决问题的根源.我收到以下错误堆栈:

在此输入图像描述

当我反映出我的dll时,我可以看到以下内容

在此输入图像描述

阅读http://blogs.teamb.com/craigstuntz/2010/08/13/38628/它表明我希望在这里看到csdl,msl和ssdl文件,但它们不是.它们确实存在于obj\Debug\edmxResourcesToEmbed中.

从来没有我试过通过这样做明确告诉web.config在哪里看:

...connectionString="metadata=res://DllName.dll/PaymentModel.csdl|res://DllName.dll/PaymentModel.ssdl|res://DllName.dll/PaymentModel.msl;provider=System.Data.SqlClient;provider ... />
Run Code Online (Sandbox Code Playgroud)

哪个只是抛出一个错误,说它无法找到dll:

无法解析程序集"DllName.dll".

非常类似于这个未解决的SO问题无法解决程序集Model.dll

我尝试的最后一件事是将元数据行更改为:

...connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider ... />
Run Code Online (Sandbox Code Playgroud)

这引发了一条关于我不使用的sql ce的消息 - 有没有办法绕过这个?

在此输入图像描述

还有什么我可以尝试的吗?或者任何人都可以看到我哪里出错了?一些额外的细节:

  • 使用EF 6 EDMX设置为"嵌入式资源"

  • 复制到输出目录:"不要复制"

  • 元数据工件处理:"嵌入输出程序集"

最后在此 - 如果我将EDMX从Embedded Resource设置为EntityDeploy,那么这将在本地工作但不在构建服务器上构建,因为它会抛出与此SO问题完全相同的错误:

无法找到要嵌入为输入文件资源的Conceptual Schema节点

但修复似乎没有帮助,遗憾的是我无法在服务器上安装.NET 4.5.

小智 42

我曾经也有过一样的问题.使用EF模型移动.edmx文件以分离程序集提到的错误导致我头痛:"无法加载指定的元数据资源".

EF版本6.1

解:

旧价值:

metadata=res://*/Data.DataModel.csdl
Run Code Online (Sandbox Code Playgroud)

新价值:

metadata=res://*/DataModel.csdl
Run Code Online (Sandbox Code Playgroud)

最初.edmx在项目的文件夹下,我已将其移动到项目的根目录中.


Ste*_*ead 15

So I've got to the bottom of this, partly I think this was my fault. I'll put solutions to each issue I encountered below in case it helps anyone else.

Unable to load the specified metadata resource issue

This was caused by me setting the 'Metadata Artifact Processing' setting on the edmx model from "EntityDeploy" to "Embedded Resouce".

So this meant it just embedded the whole edmx file file into the dll and didn't generate the ssdl, msl and csdl files instead.

I guess you have to set this to EntityDeploy for this to work and generate these files correctly. Makes perfect sense and our bad over here.

Unable to resolve assembly 'DllName.dll'

This was resolved by Andrew in the comments above, thanks for the pointer on that.

Could not find the Conceptual Schema node to embed as a resource for input file

The key to this whole issue really is this, our build server is currently on Windows 2003, so can't have .NET 4.5 installed, locally we were using EF 6.1 running under .NET 4.0 on VS2013.

However for some reason it looks like we need to have .NET 4.5 installed on our build server to get this to build even though we're not using any of the 4.5 features and targetting the .NET 4 framework.

Downgrading to EF to 4.3 solved this issue for us in the short term. Not ideal but it worked.


And*_*rew 13

您应该指定程序集完全限定名称和模型文件的路径(由...分隔/),而不是dll名称

connectionString="metadata=res://Name.Of.The.Assembly, Culture=neutral, PublicKeyToken=8e2e51fcf4cf363e/Payment.PaymentModel.csdl|.........."
Run Code Online (Sandbox Code Playgroud)

同样的ssdlmsl


小智 9

更改元数据

connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;
Run Code Online (Sandbox Code Playgroud)

connectionString="metadata=res://*/;
Run Code Online (Sandbox Code Playgroud)

上述更改将解决问题


小智 7

解决方案:
1)从visual studio打开.edmx文件.
2)点击任意位置.
3)应该看到edmx属性窗口.
4)将命名空间更改为正确的文件夹名称.
5)1:https://i.stack.imgur.com/6sZvo.png(选择图像了解更多详情).


小智 7

我有同样的问题

System.Data.MetadataException:无法加载指定的元数据资源

原来产生的Connection字符串上面带有所有edmx的名称。我从连接字符串中取出了所有模型名称,仅在元数据中保留了以下字符串

"metadata=res://*/;provider=System.Data.SqlClient;provider
Run Code Online (Sandbox Code Playgroud)

这对我有用。


Dee*_*101 5

如果您使用的是dotnetCLI

对于使用新dotnet build工具来构建基于Entity Framework 6.x的项目的新访客,要知道它目前不会在最终版本中嵌入任何元数据。因此,如果您从VS中运行,它将运行,但是如果您使用CI脚本,dotnet则它们将在服务器上失败,直到您切换回msbuild。恕我直言,这是一个错误,工具应该可以解决。如果需要,您可以在GitHub线程上发出提示音。