When we use a ADO.NET Entity Data Model (.edmx file) inside a ADO.NET Data Service (.Svc) file in a WebApplication project, we get an Exception saying that “Unable to load the specified metadata” whereas this works just fine in a website project.
More Details & Solution:
If we create an ADO.NET Data Service inside a Web Application project (WAP), and if we attempt to set a Entity Model as the data source for the said service, while running the application we would get an exception saying that “Unable to load the specified metadata”. Common causes that are attributed to this are connection string issues, Etc. But the real solution is bit deeper.
We have a property called “Metadata Artifact Processing” for the .edmx and by default its value is set to “Embed in Output Assembly” – We need to change this to “Copy to Output Directory” and in the subsequent runs the exception no longer occurs.
With the same value “Embed in Output Assembly” for the property “Metadata Artifact Processing” everything works fine in a WebSite Project (WSP). In fact it is the only option available in a WSP for this property value. Our assumption/reasoning here is that as the Class file of the .svc as well as the .edmx are by default located in the “App_Code” folder of the WSP, the .NET runtime compiles everything in the App_Code folder of the WSP. Whereas with the WAP, there is No “App_Code” folder present and we have to explicitly set the .edmx to copy the metadata to the output directory.