Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Metadata Exception in Entity Framework Connection Strings
WhatsApp
Guest User
13y
31.3
k
0
0
25
Blog
After generating the entity model and classes for my existing SqlCe database, I tried to run some LINQ queries against it. The following exception was thrown as soon as I tried to instantiate the ObjectContext:
unable to load the specified metadata resource
The metadata that the error message refers to is in the connection string. This was automatically generated for me, so why would it fail? After lots of googling, I found
this page on Craig Stuntz's blog
that has some very handy troubleshooting tips. He lists several possibilities as to why the metadata would be the cause of the error, but in my case it was the use of the asterisks in the paths in the embedded resources:
metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl
As Craig points out, it is better to replace the asterisks with the explicit name of the assembly that contains the model as in:
metadata=res://MyDAL/MyModel.csdl|res://MyDAL/MyModel.ssdl|res://MyDAL/MyModel.msl
If this doesn't work for you, you may need to use a tool such as Reflector to find the exact path of the resources within the compiled DLL. In my case, my model was in a sub-directory of the DAL project (named "Client"), so my metadata now looks like this:
metadata=res://MyDAL/Client.MyModel.csdl|res://MyDAL/Client.MyModel.ssdl|res://MyDAL/Client.MyModel.msl
I haven't encountered the metadata exception since I made this change.
Metadata Exception in Entity Framework Connection Strings
Up Next
DbSet.AddRange and DbSet.RemoveRange in Entity Framework 6.0
Ebook Download
View all
DateTime in C#
Read by 1.3k people
Download Now!
Learn
View all
Membership not found