Albert Bori
Albert Bori

Reputation: 10002

MVC 4 Add Controller Error Unable to retrieve metadata for my Model

I recently added a MVC4 Web Application to my solution and gave it a reference to my Common class library. The Common class library contains the models and context (EF Code First).

When attempting to use Visual Studio's scaffolding feature to "Add Controller" to the MVC4 Application, I get the following error:

Unable to retrieve metadata for 'Common.Models.MyContext'. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

I have found a lot of similar questions on stack overflow, but none of them address this specific error message for this specific scenario.

In my investigations, I found that if I remove all the added packages and third party dll's from the Common library, I am able to use the "Add Controller" function without error. This tells me that one of my packages or third party dll's is not where it needs to be (as indicated by the error message).

So my questions are these:

  1. How do I find out which dll is causing the problem? Is there a Visual Studio scaffolding log file somewhere?
  2. Say that I find the offending dll... Where would the dll need to live to fix the scaffolding error?

Upvotes: 0

Views: 2297

Answers (2)

Gabriel Gómez
Gabriel Gómez

Reputation: 311

If you are using separates projects, check if EF has the same version number!

Upvotes: 0

viperguynaz
viperguynaz

Reputation: 12174

Make sure your web application project has ALL the required references from other projects. Just because your Common project has a dependency on a DLL doesn't mean that reference will be copied to your web project. You will have to add the dependant DLLs manually as references with Copy Local set to "true"

Upvotes: 3

Related Questions