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.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Mahesh ChandPosted Feb 2, 2012, 9:42 PM
Fingers crossed :)
Mahesh ChandPosted Feb 2, 2012, 9:42 PM
Fingers crossed :)