By J. Steen

2009-03-27 11:15:08 8 Comments

All of a sudden I keep getting a MetadataException on instantiating my generated ObjectContext class. The connection string in App.Config looks correct - hasn't changed since last it worked - and I've tried regenerating a new model (edmx-file) from the underlying database with no change.

Anyone have any ideas?

Further details: I haven't changed any properties, I haven't changed the name of any output assemblies, I haven't tried to embed the EDMX in the assembly. I've merely waited 10 hours from leaving work until I got back. And then it wasn't working anymore.

I've tried recreating the EDMX. I've tried recreating the project. I've even tried recreating the database, from scratch. No luck, whatsoever.


@Amol Aher 2019-09-27 04:39:24

I had same issue on 27 Sep 2019.

My API is in Dot net core Targeting to .net framework. edmx is in a different class library which is in .net framework only.

I observed that when I try to call that edmx from API .. for some reason I got that error.

What I did is, go to the obj folder of API and delete everything. then clean the API project and try again and that worked for me.

@MOH3N 2018-08-06 05:06:31

Sometimes i see this error in my project. I solve that by

1 - Right click on EDMX file

2 - Select Run Custom Tool option

3 - Rebuild project

@rdans 2019-03-20 13:52:58

This worked for me but I also had to rebuild afterwards

@Yogesh Sharma 2019-01-18 00:47:23

I also face this issue, I just clean and rebuild solution which works fine.

@Liakat 2018-06-25 01:48:56

This happens to me when I do not clean solution before build new .edmx designer. So just don’t forget to clean solution before you build new .edmx designer. This helps me to skip lot more issues with this one. Bellow the navigation details provided incase you are new in visual studio.

Click->Build->Clean Solution

Then Click->Build->Rebuild Solution

Hope this helps. Thanks everyone

@radkan 2018-05-24 19:42:28

In my case none of the answers listed worked and so I'm posting this.

For my case, building on Visual studio and running it with IIS express worked fine. But when I was deploying using Nant scripts as a stand-alone website was giving errors. I tried all the suggestions above and then realized the DLL that was generated by the nant script was much smaller than the one generated by VS. And then I realized that Nant was unable to find the .csdl, .msl and .ssdl files. So then there are really two ways to solve this issue, one is to copy the needed files after visual studio generates them and include these files in the build deployment. And then in Web.config, specify path as:


This is assuming you have manually copied the files into bin directory of the website which you are running. If it's in a different directory, then modify path accordingly. Second method is to execute EdmGen.exe in Nant script and generate the files and then include them as resources like done in the example below:

@Graham Laight 2018-01-24 16:39:29

If you are using the edmx from a different project, then in the connection string, change...



@qakmak 2019-05-10 22:22:23

This is true, If you want to move it to your new project sub folder, you need to add the folder.subfolder before it.

@Chris 2019-10-22 12:03:25

Thanks, this solution worked for me. I had moved my .edmx file from a dir in one project, to the root of another project, and needed to remove the dir name from all connection strings across my solution.

@Craig Stuntz 2009-03-27 12:02:19

This means that the application is unable to load the EDMX. There are several things which can cause this.

  • You might have changed the MetadataArtifactProcessing property of the model to Copy to Output Directory.
  • The connection string could be wrong. I know you say you haven't changed it, but if you have changed other things (say, the name of an assembly), it could still be wrong.
  • You might be using a post-compile task to embed the EDMX in the assembly, which is no longer working for some reason.

In short, there is not really enough detail in your question to give an accurate answer, but hopefully these ideas should get you on the right track.

Update: I've written a blog post with more complete steps for troubleshooting.

@J. Steen 2009-04-29 11:26:31

The connectionstring, despite my efforts to compare it with a content-compare utility last time, was wrong.

@Ray 2010-10-24 22:45:41

It was the connectionstring for me too. When you have Integration Tests that also need connectionsting in its own App.config, things may go out of sync when you update your edmx.

@Shimmy Weitzhandler 2010-12-07 02:50:54

yes, I did change the settings of the MetadataArtifactProcessing and the post-compile etc. so how do I fix the problem?

@Shimmy Weitzhandler 2010-12-07 03:12:09

OK, I fixed it by simply setting "Embed"; compiling, then reseting it to the other one. That solved my problem.

@MemeDeveloper 2011-08-07 20:54:38

If it is the connection string, and you are doing "DB first" you can tell easily enough (in most cases) by comparing what you get when you "update from database" in the edmx designer with what you have in your web.config or app.config.

@Tony_Henrich 2011-11-10 23:37:45

In my case, I excluded the edmx from the project because I thought I didn't need it anymore (I used the dbContext generator). The edmx didn't get included as a resource in the assembly. The fix was to include it.

@Samvel Siradeghyan 2012-08-31 20:35:14

Fantastic!!! I changed conntection string to metadata=res://*/;provi.. and it worked!!

@Episodex 2012-10-23 14:59:27

Had the same problem, tried your solution, wanted to give +1, realised I already did it in the past. I don't even remember having this problem before ;). This time in my case it was correct connection string in Class Library with edmx and wrong in web application when it was used.

@emragins 2013-05-25 00:25:19

Awesome guide. For me, I'd copied another connection string which used res://*/Database.MyModel2..., when I REALLY wanted res://*/MyModel1... (Database is a folder inside my Integration Tests project)

@Chlebta 2014-04-22 22:52:32

How to know the Assemblie file ?

@user836107 2014-06-24 14:27:30

Check for entityframework dlls are referenced and copy&paste the connection string from the library as is.

@Baby 2014-08-18 08:41:11

after following this steps, i got this error "The entity type Department is not part of the model for the current context."

@Mark_Gibson 2014-09-12 10:44:18

In my case, I had moved the edmx to a different folder and correctly changed the res paths in web.config, but I hadn't changed them in the web.debug.config and web.release.config transformations

@phillihp 2014-12-15 21:44:57

Thanks @Shimmy for sharing your own fix. What you shared at 3:12 worked for me as well. Plus one to you for taking the time to return to the post and share your fix!)

@PeterX 2015-01-05 01:21:24

I moved the EDMX file to a sub-folder, but am unsure how to fix it. I've ran Run Custom Tool on the TT file, but it hasn't resolved it.

@Anonymous 2015-01-23 07:57:22

Link on the update section is really helpful. Thanks!

@Legends 2015-04-05 22:21:52

In my case it was a db table column of type geography, which is not supported

@Nathan 2016-01-21 15:49:50

Going off of what Shimmy said, I changed MetadataArtifactProcessing from embed (which was correct) to copy (which is wrong), rebuilt the project, cleaned the bin folder manually, changed it back to embed, rebuilt, and it worked. As a side note, get to the MetadataArtifactProcessing by right clicking in an open area of the edmx designer and selecting "Properties" from the context menu.

@Vova 2016-03-02 18:42:18

After I have refactored database name and replaced it in code at all places have got mentioned exception. Was able to easily update model from database at database tier related project, however after deployment exception always was thrown as there was used different config file. Have used connection string from from project with model at project for deployment and issue was fixed.

@Dr. MAF 2017-03-09 12:33:41

While creating the ADO data model, I didn't accept the default naming values and modified some. This caused the connection string to have strange values. I repeated the same process, accepting all default values this time. Works perfect. Thanks

@Dov Miller 2017-07-27 13:13:18

Your blog helped me. The paragraph "Which Config File?" did it. The connection string in the web.config was wrong even tho in the app.config that I thought was being was right. Fixed the web.config conection string and that solved it. Thank you.

@James S 2017-11-29 16:47:52

Your blog helped me understand the problem. Specifically its not that the edmx is not found, its that the embedded Metadata resources generated from the edmx are not found. At complile time Visual Studio uses a MsBuild task to compile the metadata as 3 embedded resources in the output assembly (which you can see in ILSpy). If the assembly can be found AND it contains the resources then all is well and good - but what about if you're using NANT as the compiler?... well its fixable...‌​s

@ElliotSchmelliot 2018-07-06 17:23:01

Fixed by updating the EDMX (edmx > right-click > update model from database)

@Keith 2018-07-10 14:35:57

In our case, it was resolved by performing a "Clean Solution" and a rebuild all.

@Neil Laslett 2018-11-13 16:38:26

That's twice your answer has saved my hide. I refactored my classes and moved the EDMX file. My App.config connection string was updated but my XML transform App.Release.config still had the old namespace.

@antonio 2019-02-01 11:06:14

@CraigStuntz My case: I have renamed the model.edmx (VynilHouseModel.edmx to VinyHouseMode.edmx), and, i'm using app.debug.config and app.release.config. And, the new app.config was re-created but i don't have realized.

@ismail baig 2019-02-17 09:48:51

Thanks it solved my problem, i too had connection string problem.

@RAM 2017-10-05 08:19:51

I got this problem after moving a large solution from one folder in Source Control Explorer to another. We don't check the package folder into Team Foundation and so I think VS downloaded packages automatically. This upgraded my EF form v6.1.2 to v6.1.3.

The problem went away when I downgraded to the original v6.1.2.

@Christopher Townsend 2017-03-07 17:43:51

In my case this was because I was building the connection string using a EntityConnectionStringBuilder. Make sure your Metadata property is using the Model name (including the namespace)

@Basheer AL-MOMANI 2016-08-21 16:15:03

I spent a whole day on this error

if you are working with n-tear architecture

or you tried to separate Models generated by EDMX form DataAccessLayer to DomainModelLayer

maybe you will get this error

  1. First troubleshooting step is to make sure the Connection string in webconfig (UILayer)and appconfig (DataAccessLayer) are the same
  2. Second which is Very important the connection string


    which is the problem

from where on earth I got Modelor whatever .csdl in my connection string where are they

here I our solution look at the picture

enter image description here

hope the help you

@Krishna shidnekoppa 2016-07-12 12:28:08

Exception is because compiler pointing to non existing Metadata so just Copy app.config connectionstring to Web.config ConnectionString

@MicTech 2009-07-16 12:12:23

This little change help with this problem.

I have Solution with 3 project.


change to


@Lance Fisher 2010-08-05 02:34:34

It fixed it for me, but what the heck does it mean?

@Craig Stuntz 2010-08-13 18:08:14

@Lance: I explain this in detail in this blog post

@Craig Stuntz 2012-04-06 18:17:15

@jocull: No, it won't work in many cases, and will be slow in others. Read my blog post to understand why.

@muruge 2012-06-20 05:35:05

Moved my .edmx to Model folder and forgot to update the connection string. Great pointer. Thanks. Would have taken me hours to figure out.

@The Muffin Man 2012-11-24 02:55:21

You sir have saved a poor Microsoft employee from a very pissed off consumer.

@Andrey Khmelev 2013-08-14 18:38:49

thank you, I rename my Model to Model1 in web.config and it's work!

@Michał Powaga 2013-08-25 07:19:13

I've done it, and id solved one problem but gives me another All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered. - at last for Npgsql. Only full path solved both.

@batmaci 2017-06-21 16:33:02

@MichałPowaga because this solution makes no sense when you have same named class under different namespace. it just ignores the namespace

@pepitomb 2017-06-28 20:31:55

this trick fixed my problem, I didn't remember that I've had this problem before unitl I read this solution, now I'm sure I won't forget it again

@pluto20010 2018-01-11 13:28:47

'No connection string named 'xyz' could be found in the application config file.'

@Michael Freidgeim 2019-01-22 01:03:26

@CraigStuntz, the link to your blog is broken

@Craig Stuntz 2019-01-22 18:30:52

@MichaelFreidgeim I can't edit the comment, but here's a newer link.

@Hamza Tahir 2019-10-28 07:00:01

Thanks buddy ... Ur answer helped me to resolve the issue .

@Dinesh Wickramasinghe 2020-04-09 06:21:48

Worked for me as well. Thanks :D

@Rick Arthur 2009-12-04 05:55:00

I had a similar error. I had recreated the project (long story), and pulled everything over from the old project. I hadn't realized that my model had been in a directory called 'Model' before, and was now in a directory called 'Models'. Once I changed the connection in my Web.Config from this:

<add name="RecipeManagerEntities" connectionString="metadata=res://*/Model.Recipe.csdl 

to this:

<add name="RecipeManagerEntities" connectionString="metadata=res://*/Models.Recipe.csdl

Everything worked (changed Model to Models). Note that I had to change this three places in this string.

@Patrik Lindström 2012-01-15 15:28:34

I moved my Entity Framework model from Model to DAL. But then when I wrote a test (a week later) in the test project to test the Linq predicatebuilder. I got this error. I corrected the test projects App.config with how it looked in the main project's web.config - as you said in three places. So your simple answere got me on track.

@PeterX 2013-07-25 05:03:22

Yes thanks - check your filename(s). Somehow I had the old name.

@Erwin Rooijakkers 2013-12-02 14:05:05

Is there a difference between the two?!

@Marc 2015-08-06 14:54:21

@ErwinRooijakkers Model vs ModelS

@ruffin 2016-03-01 20:47:10

Figured out I'd done the same from after reading Craig's blog, but +1 for learning it's important to remember that changes made in your "entities" class library are not automagically made in the config files of projects that reference it. /sigh Glad I'm not alone.

@Pavel Nazarov 2016-02-12 19:31:03

Just type path as follows instead of {Path.To.The.}: res:///{Path.To.The.}YourEdmxFileName.csdl|res:///{Path.To.The.}YourEdmxFileName.ssdl|res://*/{Path.To.The.}YourEdmxFileName.msl 2016-02-09 15:05:13

I got this error when my emdx file was deleted by a prebuild command, quite simply. Took me a while before realizing it was that simple.

@ben 2015-07-29 10:27:25

After hours of googling and trying to solve none of the solutions suggested worked. I have listed several solution here. I have also noted the one that worked for me. (I was using EF version 6.1.1, and SQL server 2014 - but an older DB)

  1. Rebuilding the project and try again.
  2. Close and open VS - I don't know how this works
  3. make sure if you have placed the .EDMX file inside a Directory, make sure you include the Directories in your ConnectionString. for example mine is inside DAL folder. SO it looks like this: connectionString="metadata=res://*/DAL.nameModel.csdl|res://*/DAL.nameModel.ssdl|res://*/DAL.nameModel.msl;(these are files. to see them you can toggle Show All Files in solution explorer, under ~/obj/.. directory)

...and many more which I had tried [like: reverting the EntityFramework version to a later version(not sure about it)]

what worked for me:

from this article here, it helped me solve my problem. I just changed my ProviderManifestToken="2012" to ProviderManifestToken="2008" in the EDMX file. To do this:

Solution Explorer

  1. Right click over file .edmx
  2. Open with..
  3. Editor XML
  4. Change ProviderManifestToken="XXXX" with 2008

I hope that helps.

@Greg 2017-07-14 19:29:15

I recently had this problem after making seemingly no changes. Tried restarting VS to no avail, but then it was fixed by cleaning and rebuilding. So, to others, if you made no changes and none of the rest of this seems relevant, then give a clean/rebuild a try.

@user464507 2010-10-02 09:09:32

For my case, it is solved by changing the properties of edmx file.

  1. Open the edmx file
  2. Right click on any place of the EDMX designer
  3. choose properties
  4. update Property called "Metadata Artifact Processing" to "Embed in Output Assembly"

this solved the problem for me. The problem is, when the container try to find the meta data, it cant find it. so simply make it in the same assembly. this solution will not work if you have your edmx files in another assembly

@Mike 2013-09-20 14:24:19

+1,000,000 this was the underlying issue for me today. Pains of reorganizing a products namespaces and consolidating assemblies.

@Pitming 2009-10-12 09:42:25

I had the same problem. I looked into my complied dll with reflector and have seen that the name of the resource was not right. I renamed and it looks fine now.

@John Peters 2014-09-29 16:23:42

My issue and solution, the symptoms were the same "Unable to load the specified metadata resource" but the root cause was different. I had 2 projects in solution one was the EntityModel and the other the solution. I actually deleted and recreated the EDMX file in the EntityModel.

The solution was that I had to go back to the Web Application project and add this line into the config file. The new model had changed a few items which had to be duplicated in the "other" project's Web.Config file. The old configuration was no longer good.

     <add name="MyEntities"
                    provider connection string=&quot;
                    data source=Q\DEV15;initial catalog=whatever;
                    user id=myuserid;password=mypassword;
                    application name=EntityFramework&quot;"
     providerName="System.Data.EntityClient" />

@Jared Beach 2014-09-15 16:01:25

Using the info from this blogpost:

Like others have said, res:\\ is a pointer to your resources. To check and make sure your resource names are correct you can use a decompiler like DotPeek by JetBrains to open up your .dll file and see your Resources files.

Or you could open up the watch window while you're debugging and paste in this code to get an array of the resource names in the currently executing assembly.


That being said, the format of your metadata paths should be something like:

{my-assembly-name}/{possibly-a-namespace}.{class-name}.{csdl or ssdl or msl}

@PeterX 2014-06-27 06:18:43

I simply hadn't referenced my class library that contained the EDMX file.

@Moby's Stunt Double 2016-03-21 23:34:01

This really helped my particular circumstances, thanks @PeterX.

@MyDaftQuestions 2014-04-18 08:27:09

A poor app.config or web.config file can do this.. I had copied the app.config connection string to my web.config in my UI and ended up entering:

          <add name="name" connectionString="normalDetails"/>

@Daniel Hollinrake 2014-03-20 08:21:54

I had this problem yesterday and was looking at my code in debug and the output from SQL Profiler.

What I couldn't understand, before I read and understood this post, was why EntityFramework was throwing this error as it was calling the DB. I was looking through hundreds of lines in SQL Profiler trying to work out what was wrong with the database model. I couldn't find anything like the call I was expecting, and to be honest I wasn't certain what I was looking for.

If you are in this position, check the connection string. My guess is that before EntityFramework creates its SQL it will check the model, specified in the metadata part of the connection string. In my case it was wrong. EntityFramework wasn't even making it as far as the DB.

Make sure the names are correct. Once I got that sorted out, I was then seeing calls in SQL Profiler where the ApplicationName was 'EntityFramework' with SQL calling the expected tables.

@Rob Sedgwick 2014-02-13 13:06:29

Similar problem for me. My class name was different to my file name. The connectionstring generated had the class name and not the file name in. Solution for me was just to rename my file to match the class name.

@leqid 2013-11-13 16:57:43

And a quick way to check the model name without Reflector.... look for the directory

...obj/{config output}/edmxResourcesToEmbed

and check that the .csdl, .msl, and .ssdl resource files are there. If they are in a sub-directory, the name of the sub-directory must be prepended to the model name.

For example, my three resource files are in a sub-directory Data, so my connection string had to be


(versus metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;).

@Fernando Carvalhosa 2015-09-29 18:51:15

This was EXACTLY my problem. Lost several hours on this. Thank you so much for this easy explanation

@cjb110 2018-02-12 08:06:31

Great answer, actually explains how to find what your string is. And shows that subfolders have '.' as delimiters and not '\' or '/'.

@صفي 2013-10-22 13:17:57

With having same problem I re-created edmx from Database. Solves my problem.

@Clarice Bouwer 2014-01-16 06:03:05

Unfortunately that addresses and treats the symptom, not the cause.

@Jeff Dunlop 2013-09-20 10:51:27

When I got the metadata issue sorted out, I had a follow-on problem in the form of an invokation exception unable to find a connection string for XXXEntities in app.config (where my goal was no dependency on app.config). Through sheer luck I found that referencing System.Data in my unit test project cleared this final hurdle. So to summarise:

  1. Use nuget to install Entity Framework to your unit test project.
  2. Ensure System.Data.Entity and System.Data are referenced.
  3. Sort your connection string as described very well here.
  4. Pass the connection string to your partial class constructor.

I now have my metadata in a class library which can update from a reference db, and I can point my application and unit tests to any db on any server at runtime.

Addendum: When I moved my edmx to a folder, I got the error again. After a bit of research, I found that you want your metadata string to look like: metadata=res://EPM.DAL/Models.EPM.csdl, where EPM.DAL is the name of the assembly and EPM.edmx is in the models folder.

@J. Steen 2009-04-20 16:45:44

The ultimate solution (even after recreating the database on two other machines, as well as the EDMX and other sundries) was to not use the first edition of Entity Framework. Looking forward to evaluating it again in .NET 4.0.

After running into the same problem again and searching all over for an answer, I finally found someone who'd had the same problem. It appears that the connection string wasn't correctly generated by Visual Studio's wizard, and the link to the metadata resources was missing an important path.

v1.0 BUG?: Unable to load the specified metadata resource. Scripts != Models

Update 2013-01-16: Having transitioned to almost exclusively using EF Code First practices (even with existing databases) this problem is no longer an issue. For me, that was a viable solution to reducing the clutter from auto-generated code and configuration and increasing my own control over the product.

@Ghlouw 2012-11-27 09:02:33

I also had this problem and it was because the connectionstring in my web.config was slightly different than the one in the app.config of the assembly where my EDMX is located. No idea why it changed, but here are the two different versions.


<add name="SCMSEntities" connectionString="metadata=res://*/Model.SMCSModel.csdl|res://*/Model.SMCSModel.ssdl|res://*/Model.SMCSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SANDIEGO\sql2008;initial catalog=SCMS;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />


<add name="SCMSEntities" connectionString="metadata=res://*/Model.SCMSModel.csdl|res://*/Model.SCMSModel.ssdl|res://*/Model.SCMSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SANDIEGO\sql2008;initial catalog=SCMS;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

What fixed it was simply copying the app.config string (notice the small difference at the end - instead of "App=EntityFramework" it wanted "application name=EntityFramework") into the web.config and problem was solved. :)

@Volkan 2018-01-29 11:00:11

Thanks, this was indeed my problem. I had 1 project that access DB with EF and another project WCF. After changing the name of the first project, the connectionString has been changed in the App.config of my first project. So i had to change the connectionString in the project WCF aswell in the web.config :)

@Suncat2000 2018-12-07 12:46:55

From MSDN documentation about…: The .NET Framework data provider for SQL Server (SqlClient) supports many keywords from older APIs, but is generally more flexible and accepts synonyms for many of the common connection string keywords. Entity Framework connection strings do not share that flexibility, so you must use only the keywords it expects.

@Frank Myat Thu 2012-11-02 02:59:59

As for me, I had separated Data Access Layer and User Interface layer. So I have entity connection string for each layer.

Before I modify these two separated connection strings to be the same, I still found that below error.

Unable to load the specified metadata resource

So I make to be the same connection strings for those two layers (DAL , UI), It work perfect.

My solution is to make all connection string to be the same no matter where they already presented.

Related Questions

Sponsored Content

86 Answered Questions

[SOLVED] Metadata file '.dll' could not be found

17 Answered Questions

[SOLVED] Entity Framework - Unable to load the specified metadata resource

37 Answered Questions

[SOLVED] Error - Unable to access the IIS metabase

39 Answered Questions

5 Answered Questions

[SOLVED] Unable to load the specified metadata resource

1 Answered Questions

[SOLVED] Entity Framwork Unable to Load the specified metadata resource

2 Answered Questions

[SOLVED] MetadataException [Unable to load the specified metadata resource]

1 Answered Questions

[SOLVED] MetadataException in Release Build

Sponsored Content