Archive for the ‘RIA’ Category

Code first and WCF RIA services: Failed to get the Metadataworkspace for the DbContext type ‘{Type}’

While working with WCF RIA services, DbContext (DomainContext), Entity Framework code first, and Silverlight, I received this error quite a bit whenever I tried to run or compile the Silverlight project. 

The error means that there is something wrong with your code first model.  For me, it was usually some attribute that had a wrong string it.

It is annoying because it’s almost impossible to fix this error without knowing the tricks. Good news though!  The way to get around this error is to browse to your WCF RIA service. 

1) In order to make your service browsable at all (at least consistently), you should make your project use IIS rather than IIS Express.  Go into the project settings, under the web tab, and make sure “Use Local IIS Web server” is selected and “Use IIS Express” is not selected.

2) Now you need to find the URL your domain service uses. 

2.a) Make sure “Show all files” is enabled at the top of your Solution Explorer window. 

2.b) In your Silverlight project, expand the folder “Generated_Code”.  Open the file at the root of that folder.  Search for “http://”.  You’ll find a URL that looks similar to:


3) Compile the web project by itself so that you have the most up to date error showing when you browse to the URL.

4) Browse to the URL!  It should give a much better error message.  Make sure you have the web project showing exception details. If you don’t, the web page will tell you how to do so.