Sunday 23 August 2009

EntityContainer name could not be found in the mapping and metadata information

Symptom

ADO.NET entity framework throws the following exception when creating an entity context:

System.ArgumentException: The specified default EntityContainer name [NAME] could not be found in the mapping and metadata information. Parameter name: defaultContainerName
at System.Data.Metadata.Edm.ClrPerspective.SetDefaultContainer(String defaultContainerName)
at System.Data.Objects.ObjectContext.set_DefaultContainerName(String value)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)

Cause

This error can mean a mismatch between the metadata referenced in the connection string (i.e., in config) and theembedded resource in your assembly. You have probably noticed that entity framework connection strings contain a much more than typical db connection strings. In fact the db connection is just one of its properties. So what are the other properties?

  1. metadata: lists the three metadata resources required by entity framework (CSDL, SSDL, MSL). For more info on these see entity framework metadata resources.
  2. provider: the .Net data provider
  3. provider connection string: the underlying db connection string (this is the 'typical' ado.net connection string). Note that this string is quoted inside the EF CS using "
Now if the names of any of the resources in the metadata property don't match the resources actually embedded in your assembly, then you'll get this error. How do I tell what the names of the embedded resources are? Open your assembly using .Net Reflector. Look under resources - you should see the three EF metadata resources. Check your connection string and make sure they match.

14 comments:

Jonas Stensved said...

This helped me a lot. Visual Studio refactored my connection string (behind the scenes) which resulted in an error.

Thank you :)

Anonymous said...

Many thanks. That solves my problem without spending too much time digging around.

Jerry Odom said...

Great post. Quick solution to a silly problem that could've given me an all day headache. These WCF services don't give very good debugging clues.

Anonymous said...

Thanks a lot, this helped me, in resolving my problem. :) :)

Anonymous said...

I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an shakiness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike.

My weblog new star trek movie

Anonymous said...

Thanks a lot, it helped me. :)

Anonymous said...

I'm curious whіch blogging ɑnd site-building platform
yօu aгe running? I'm new to operating ɑ blog and havе been thinking about usіng the Live journal platform.

Ɗo yoս cоnsider this is a gօod foundation tto start ԝith?
I would be extremely grateful if I сould assk yօu ѕome questions tɦrough email sο I ccan learn a
bit mօre prior tο gettimg started. Whеn you ɦave ѕome
free time, рlease be surde to contact mе at: wilhemina.mckerihan@bigstring.ϲom.
TҺanks alot :)

Feel free tߋ surf tօ my website Where to Get Hay Day Hack

Anonymous said...

I am regular reader, how are you everybody? This article posted at this web
page is really fastidious.

Also visit my blog post :: Skin Lift REviews

Anonymous said...

Write more, thats all I have to say. Literally, it seems as
though you relied on the video to make your point.
You clearly know what youre talking about, why throw away your intelligence on just posting videos to your site when you could be
giving us something informative to read?

my blog post - ketone weight loss - http://www.raviapeligro.com/activity/P/90169,

Anonymous said...

Very nice post. I just stumbled upkn your weblog and wished
to say that I ave really enjoyed surfing around your blog posts.
After all I'll be subscribing to your feed and I hope you write
again soon!

my webpage: polaris snowmobile helmets

Anonymous said...

I do trust all of the ideas you have offered for your post.
They're really convincing and will definitely work.
Nonetheless, the posts are very quick for beginners. May you
please prolong them a bit from subsequent time? Thank you
for the post.

Feel free to visit my web-site anh cuoi dep

Anonymous said...

Incredible quest there. What happened after? Thanks!



My blog veg recipes

Anonymous said...

Vivement un аutre article

Here is my site :: vidéo érotique

Anonymous said...

Pretty nice post. I just stumbled upon your blog and
wanted to say that I'vetruly enjoyed browsing your blog posts.
After all I'll be subscribing to your rss feed and I hope you write again soon!

My page: Dr Rashmi Patel dental license suspended ()