find a location for property in a new city

Thursday, 24 June 2010

Entity Framework MetadataException: Unable to load the specified metadata resource

I got a "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation" error with a description of "System.Data.MetadataException: Unable to load the specified metadata resource. at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources".

This occurred when I was trying to move my Models out of my main MVC web application assembly. The main web dll is called Web and within that project is a folder called Models that is used to store all my *ahem* Models and entity data models etc. I decided to move everything in the Models folder out into its own Models assembly. I edited all the namespaces and everything built okay.

However, I was getting a runtime MetadataException when trying to view the page. What the hell is going on?!

Solution

The problem is that the connection string was incorrect. It wasn't immediately obviously with that error message but when you think about it, it makes sense.

My connection string was: connectionString="metadata=res://*/Models.Messaging.MessagingObjects.csdl|res://*/Models.Messaging.MessagingObjects.ssdl|res://*/Models.Messaging.MessagingObjects.msl;....etc"

Just so you know the metadata represents this metadata=res://{assembly}/{namespace}.{filename}.csdl|res://{assembly}/{namespace}.{filename}.ssdl|res://{assembly}/{namespace}.{filename}.msl;

Since I have moved the models around and the namespace is now different I needed to make it connectionString="metadata=res://*/Messaging.MessagingObjects.csdl|res://*/Messaging.MessagingObjects.ssdl|res://*/Messaging.MessagingObjects.msl;

Just for further understanding I could have replaced the asterix with Models since that is the name of the dll that contains my Messaging models.

Follow britishdev on Twitter

6 comments:

  1. Thanks for the post, solved my issue I was having!

    ReplyDelete
  2. Great, I had exactly the same problem right now and solved it with your help. thank you so much!

    ReplyDelete
  3. Thank you so much...did not consider it at all...

    ReplyDelete
  4. I am using model first. I generated the domain classes and moved them into a separate project. I also move the context to a separate class. I changed my app config file to add the namespace. I still get the message. I also tried adding the assembly name. That caused a different problem. I have the app config file in my model, domain and context assembly. Same config file in each case. My config file is:






    ReplyDelete
  5. Nice post, helped me figure this app out!! Thanks!!

    ReplyDelete