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

15

35

My connection strings are as follows:

<add name="RollCallDBEntities" connectionString="metadata=res://System.Engine/RollcallNS.csdl|res://System.Engine/RollcallNS.ssdl|res://System.Engine/RollcallNS.msl;provider=Devart.Data.Oracle;provider connection string=&quot;User Id=user;Password=password;Server=127.0.0.1;Direct=True;Sid=ORCL&quot;" providerName="System.Data.EntityClient" />

my code are as follows:

using (var db= new RollCallDBEntities()) //ok
{
   var query = db.TBL_ROLLCALL.ToList(); //Unable to load the specified metadata resource.
}

my assembly:

System.Engine

Anyone have any ideas?

these links did not soled my problem:
MetadataException: Unable to load the specified metadata resource
entity framework Unable to load the specified metadata resource
Entity Framework: Unable to load the specified metadata resource
Unable to load the specified metadata resource

Babushka answered 21/8, 2013 at 7:59 Comment(5)
Are you sure that the resources were embedded in the assembly? Use ildasm or reflector to double check they are there.Reamer
Another thing you can try is to replace 'System.Engine' with '*' in all three places.Reamer
@Reamer TBL_ROLLCALL are as follows namespace System.Engine { using System; using System.ComponentModel; using System.Data.Objects.DataClasses; using System.Runtime.Serialization; using System.Xml.Serialization; [Serializable, EdmEntityType(NamespaceName="RollCallNS", Name="TBL_ROLLCALL"), DataContract(IsReference=true)] public class TBL_ROLLCALL : EntityObject {...Babushka
this does not answer my question I was asking about resources embedded in the assembly and not about the class itself since the exception indicates the problem is with the resources.Reamer
@xanatos i undelete the questionBabushka
B
8

Refer to http://forums.devart.com/viewtopic.php?t=22092 .

If this doesn't help, please specify:

  • are you working with ADO.NET Entity Data Model (.edmx) or Devart Entity Model (.edml)?
  • the value of your model file's Build Action property
  • the value of the Metadata Artifact Processing property of your model
  • the build number (x.xx.xxx) of your dotConnect for Oracle
  • the version of your Visual Studio
  • follow Pawel's advice to check if resources were embedded in the assembly
Benevento answered 26/8, 2013 at 10:6 Comment(0)
L
84

I was getting an exception like this. The problem was that I renamed my .edmx file and forgot to change the name in EF Web.config file's connection string:

metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;
Lenhard answered 5/11, 2013 at 19:3 Comment(6)
exactly. if you have a different project to access your data remember that you should have also 2 different connection strings... thanks for the tipMedorra
thank you ... Someone copy paste connection string for another context pointed to the same DB. So the EDMX was wrong!Merv
In my case, I move the .edmx file to another location and forget to change the connection string to point to the new location of .edmx filesGramme
Do not forget to specify DB entity's namespace in the metadata sectionLinolinocut
@Linolinocut how do I do that? can you provide a sample?Barbabra
@NitinSawant connectionString="metadata=res://*/+++.ModelName.csdl|res://*/+++.ModelName.ssdl|...", where +++ - is a namespace's name of entity model. Often folks forget to add/change it.Linolinocut
Q
11

The easiest solution that resolved this for me was to remove the obj folder which sit at the same level as the bin folder and re-run the application, my god it took way longer than it needed

Quiet answered 7/5, 2018 at 21:16 Comment(6)
Which obj folder? The one is inside presentation and the other is inside DALReplevin
@ZeeshanAhmadKhalil the one for the project throwing the errorQuiet
Thanks, I got it fixed by copying the connection string from App.config to Web.config.Replevin
I got it fixed by copying the connection string from App.config to Web.config same as Zeeshean aboveFormicary
Was getting the same problem in my web application, this helped, thanksScevo
Running an old old .net 4.5 framework proj and this saved me a lot of time!Debbradebby
B
8

Refer to http://forums.devart.com/viewtopic.php?t=22092 .

If this doesn't help, please specify:

  • are you working with ADO.NET Entity Data Model (.edmx) or Devart Entity Model (.edml)?
  • the value of your model file's Build Action property
  • the value of the Metadata Artifact Processing property of your model
  • the build number (x.xx.xxx) of your dotConnect for Oracle
  • the version of your Visual Studio
  • follow Pawel's advice to check if resources were embedded in the assembly
Benevento answered 26/8, 2013 at 10:6 Comment(0)
S
3

right click on the project>>Clean>> and then Rebuild

worked for me

Socinus answered 30/4, 2021 at 14:37 Comment(0)
U
2

I used EntityFramework 6.0 in one solution which included multiple projects such as WebSite level project, DataAccess level project. In my solution, the migrations should be happened in DataAccess level project.

When I run Add-Migration command in Package Manager Console, raised "Unable to load the specified metadata resource".

Finally, I found I set the WebSite level project as "Startup" project and this trigger above exception. It seems system will auto checking the connection string settings in the StartUp project first. And my data connection string set in WebSite level project is

"metadata=res:///ApplicationEntities.csdl|res:///ApplicationEntities.ssdl|res://*/ApplicationEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=YourDatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""

which is not correct for code first.

The correct connection string should be:

"Data Source=.;Initial Catalog=YourDatabaseName;Integrated Security=True"

Conclusion, always check the "connectionStrings" section in web.config in the "StartUp" project of solution first.

Ultrasonics answered 17/3, 2016 at 5:13 Comment(1)
Thank you. Copying the connection string from the EF project to the entry point project's config file solved the problem.Oxymoron
L
2

I also encountered this problem and it was because I was going from Entity Framework Model First to Entity Framework Code First, and had forgotten to change the EDMX connectionstring to a 'regular' connection string.

Luce answered 9/2, 2019 at 19:37 Comment(0)
I
1

This answer is specific for Devart Entity developer edml file.

When I upgraded the csproj format(Visual studio 2017 with simple format) I got this error. The csproj has a feature where you don't need to include each file instead it includes all the relevant files under the folder by default so the entity framework files are treated same way as cs files so those are not embedded into the assembly by default.

I need to manually change the build action of my edml file to 'DevartEntityDeploy' which resolved my problem.

enter image description here

Iberian answered 19/4, 2019 at 20:37 Comment(0)
B
1

I had the error with Devart DotConnect for Oracle 8.5. I just

  1. renamed the extension edml -> edmx and;
  2. changed the associated DevartEntityDeploy property of the file to EntityDeploy and the error disapeared.

Not that you can easily spot this error without browsing your website by analyzing the content of your data access Dll with JustDecompile/DotPeek/DnSpy looking for the ressource folder filled with *dl files:

DotPeek dll listing

If the Resources folder is empty or missing, you will have this error.

Blas answered 9/1, 2020 at 15:33 Comment(0)
D
1

We upgraded from .net core 1 to 3.1 and from visual studio 2015 to visual studio 2019. We noticed that the Build Action for some files has been reset. So we changed back the Build Action from None to Content for all files ending with .tt, and their Copy to Output directory to Do Not Copy.
We also had to change the build action of the .edmx file to EntityDeploy and its copy to output directory value to Do Not Copy.
HTH someone.

Diapositive answered 26/10, 2020 at 10:15 Comment(0)
E
0

If you are unsure of what the correct path is for your Metadata files, you can find out by compiling your application, then opening the DLL using JetBrains' dotPeek and looking in the Resources folder to find the .csdl etc. file.

Equalitarian answered 27/2, 2015 at 0:14 Comment(0)
A
0

I also encountered this problem and it was because I forgot to reference the project that contained the EDMX file.

Aconite answered 23/12, 2017 at 19:13 Comment(0)
L
0

I've had a similar product with devart mysqlconnect - maybe this might help.

I have a project called EFModels which contains the .edml file and is referenced by other projects.

I noticed that the Release version of a project that referenced EFModels contains the EFModels.dll but it was much smaller in size (127kb vs 437kb) than the Debug version of EfModels.dll. Moving the EFModels.dll from the debug version into the Release version solved the issue for me as for some reason the Release version did not embed the ssdl etc.

Liu answered 21/2, 2018 at 20:16 Comment(0)
F
0

I also encountered this problem becaue I was the missing entityFramework config section in the app.config.

I had this:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

But not this:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
</entityFramework>
Flambeau answered 2/5, 2019 at 18:55 Comment(0)
D
0

I had the same problem and, in my case, the problem was on changing the Model and the file named "...Web Deploy.pubxml" had the "metadata=res:///Models.**.csdl", etc. with the incorrect name (not updated). After manual correction it worked!

Dom answered 14/8, 2020 at 15:14 Comment(0)
L
0

In my case excluding the .edmx file and including it worked!

Lesialesion answered 30/12, 2020 at 21:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.