MetadataException: Unable to load the specified metadata resource

Posted by on Jun 29, 2016 in, MVC, PowerShell

I recently came across an error in a .net application where the message was as follows:

It took a fair bit of digging but eventually found the underlying cause.
My suspicions were that it was DB related due to the point in my application that it was failing. However, where/why I wasn’t sure.
After a while I discovered the source of the problem. Entity Framework, in its wisdom, breaks down an EDMX into three constituent parts, a CSDL, SSDL and MSL. These are all strongly typed to the same namespace as your EDMX and thus the Entity Framework connection string will start something along the lines of:

Where is obviously the namespace that corresponds to your EDMX. If these do not align, then Entity Framework will not know which embedded resource to load your EDMX from and thus you will.

In my case, I was transforming the connection string using Powershell to add in some environment specific variables and mistakenly changed the resource names, hence this error. Therefore, if you run in to the problem of Unable to load the specified metadata resource, be sure to check this first!