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.