Question

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.

Était-ce utile?

La solution 2

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.

Autres conseils

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.

you should specify the assembly fully qualified name and a path to your model file within it(separated by /), not the dll name

connectionString="metadata=res://Name.Of.The.Assembly, Culture=neutral, PublicKeyToken=8e2e51fcf4cf363e/Payment.PaymentModel.csdl|.........."

the same for ssdl and msl

Change the metaData

connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;

To

connectionString="metadata=res://*/;

The above change will fix the issue

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.

Solution :
1) Open .edmx file from visual studio.
2) Click anywhere.
3) Should see edmx property window.
4) Change Namespace to the correct folder name.
5) 1: https://i.stack.imgur.com/6sZvo.png (select image for more details ).

If you're using the dotnet CLI

For newer visitors using the new dotnet build tooling to build Entity Framework 6.x based projects, know that it currently does NOT embed any metadata into the final build. So if you run from within VS it'll run, but if your CI scripts use dotnet then they will fail on the server until you switch back to msbuild. IMHO, this is a bug and the tools should handle this. You can chime on the GitHub thread if needed.

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.

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"/>

Also, be aware when moving the edmx file from say a web application to a data layer, (web.config - connection / app.config - connection) that you change the connectionstring in the data layer AND the webservice layer. (else one uses two different connection strings, and this causes such a problem)

The connection string "metadata=res" should be same as Edmx name. eg

metadata=res://*/EmployeeModel.csdl 

this EDMX name should be EmployeeModel

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 :)

I hit this issue and it has bit me many, many, many times and I always forget how I fix it.

All I had to do is set the default.aspx as the start page.

Obviously this won't help everyone but in my case I have gone down the road of checking my config, connection string...

Hope this help someone, or at least the next time I google it I will find my fix. :)

I have used EF6 in my visual studio 2013. I have solved this by doing the following steps.

  • Right click on the Entity model
  • Open with XML(Text) editor
  • in tag set ProviderManifestToken="2008"
  • build solution

Hope it works for you..

I want to share my experience on this and how I solved it. In my case it happens because I copy and pasted my connection string on production server. My application was using Entity framework.

Problem was on metadata

I named my entity model as 'BetModel' but on my connection string I was using 'Entity' - 'res:///Entity.csdl|res:///Entity.ssdl|res://*/Entity.msl' on 'metadata' (reason was because i copy pasted it).

So my wrong ConnectionString was:

connectionString="metadata=res://*/Entity.csdl|res://*/Entity.ssdl|res://*/Entity.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework&quot;"

and the corrected ConnectionString was:

<add name="BetEntities" connectionString="metadata=res://*/BetModel.csdl|res://*/BetModel.ssdl|res://*/BetModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

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.

If you're trying to use more than one EDMX file and you have to put your new EDMX file in it's own namespace due to conflicts, when creating the EDMX file take note of the metadata the wizard shows you. That one is the correct one.

Then later if you are using EntityConnectionStringBuilder and are setting the Metadata there make sure you take into account the new namespace.

None of the answers here helped me as I had: /EDMX1 /Namespace/EDMX2

and while the metadata for the EDMX1 is "edmx1.csdl|edmx1.ssdl|edmx1.msl" The metadata for EDMX2 is "Namespace.edmx2.csdl ..."

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top