Monday, March 21, 2011

Entity Framework 4: Unable to load the specified metadata resource

After some refactoring, my integration tests started to fail with the following error message:
“Unable to load the specified metadata resource.”
I found out that the error was raised when I initialized the Entity Framework datacontext.  It looked like that EF couldn't find my meta description files(csdl , msl, ssdl files). So where did they go?
image

I opened up Reflector, and browsed to the DLL where my datacontext was stored. I noticed that the name of the files was prefixed with an extra DB part. This was caused because I had moved the context file under a new subfolder inside the Visual Studio project. After I updated the connection string information, all tests were green again.

<connectionStrings>
<add name="EventsEntities" connectionString="metadata=res://*/DB.EventsModel.csdl|res://*/DB.EventsModel.ssdl|res://*/DB.EventsModel.msl;provider=..." />
</connectionStrings>

No comments: