Entity Framework - Unable to load the specified me

2019-02-04 01:27发布

I realise that this has been asked a number of times but I just can't seem to get the bottom of my issue. I'm getting the following error stack:

enter image description here

When I reflect out my dll I can see the following

enter image description here

Reading http://blogs.teamb.com/craigstuntz/2010/08/13/38628/ it suggests I'd expect to see the csdl, msl and ssdl files here, but they're not. They do exist here obj\Debug\edmxResourcesToEmbed though.

Never-the-less I tried to explicitly tell the web.config where to look by doing this:

...connectionString="metadata=res://DllName.dll/PaymentModel.csdl|res://DllName.dll/PaymentModel.ssdl|res://DllName.dll/PaymentModel.msl;provider=System.Data.SqlClient;provider ... />

Which just throws an error saying it cannot find the dll:

Unable to resolve assembly 'DllName.dll'.

Very similar to this unresolved SO question Unable to resolve assembly Model.dll

The final thing I tried was to change the metadata line to:

...connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider ... />

This threw a message about sql ce which I'm not using - is there a way to get round this??

enter image description here

Is there anything else I can try? Or can anyone see where I'm going wrong? Some extra detais:

  • Using EF 6 EDMX set to "Embedded Resource"

  • Copy to output directory:"Do not copy"

  • Metadata artifact processing: "Embed in output assembly"

Finally on this - if I set the EDMX from Embedded Resource to EntityDeploy then this will work locally but not build on the build server as it throws the exact same error as this SO question:

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

But the fix doesn't seem to help and I can't install .NET 4.5 on the server unfortunately.

16条回答
放荡不羁爱自由
2楼-- · 2019-02-04 01:36

I was getting the same error. My connection string was as following

 <add name="EmployeeDbContext" connectionString="metadata=res://*/EmployeeModel.csdl|res://*/EmployeeModel.ssdl|res://*/EmployeeModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Sample;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I changed it to following and it fixed the problem

<add name="EmployeeDbContext" connectionString="server=.; database=Sample; integrated security=true;"
       providerName="System.Data.SqlClient"/>
查看更多
forever°为你锁心
3楼-- · 2019-02-04 01:38

I have had the same problem. After moving .edmx file with EF model to separate assembly mentioned error caused my headache: "Unable to load the specified metadata resource".

EF version 6.1

Solution:

Old value:

metadata=res://*/Data.DataModel.csdl

New value:

metadata=res://*/DataModel.csdl

Initially .edmx was under project's folder and I have moved it into project's root.

查看更多
手持菜刀,她持情操
4楼-- · 2019-02-04 01:38

I've hit this several times when moving between development machines after pulling down code from source control. I usually just have to explicitly rebuild the project with the EDMX file in it.

查看更多
\"骚年 ilove
5楼-- · 2019-02-04 01:40

I was having the same issue

System.Data.MetadataException: Unable to load the specified metadata resource

It turned out the Connection string which was generated earlier had all the edmx's name on it. I took out all the model names from the connection string leaving only the below string in my metadata

"metadata=res://*/;provider=System.Data.SqlClient;provider

This worked for me.

查看更多
做自己的国王
6楼-- · 2019-02-04 01:40

I actually received this identical error because my Entity Framework connection string was pointing to a valid database however it was the incorrrect database.

If you have the following instances in SQL Server:

  • MyDatabase1
  • MyDatabase2

Make sure that the connection string points to the same database that the .EDMX is wired up to and was generated from. Seems obvious enough, but when copying EF connection settings from 1 project to another this error was made and the net result was the Unable to load the specified metadata resource message. Once I used the correct connection string pointing to the correct database and assembly - the error was resolved.

The easiest thing to do is take the original connection string created in the .config file residing next to the .EDMX and copy where needed to make sure subtle or minor omissions/mistakes are not made causing EF to not load/connect correctly.

查看更多
来,给爷笑一个
7楼-- · 2019-02-04 01:45

I am sharing my code with another developer and he had this problem.No connection string differences. All the files OK... I fixed it by setting

  • Metadata Artifact Processing from: "Embed in Output Assembly" to "Copy to output directory" ,
  • rebuilding the project,
  • and then setting it back again.

This worked, I assume, because the individual files (CSDL/MSL/SSDL files) were created in the output directory when it used "copy to output directory". Apparently there was a bug that required them for the embedded version to work. Hope this helps :)

查看更多
登录 后发表回答