“Object reference not set to an instance of an object” when creating a new Web API controller with EF Scaffolding in Visual Studio 2012

后端 未结 5 1387
春和景丽
春和景丽 2021-01-18 16:42

I have an MVC4/Web API project, with an Entity Framework, Code First data model. When I try to create a new API Controller with read/write methods using a data context &

5条回答
  •  一生所求
    2021-01-18 17:25

    Found the problem. In my model, I had a property with a custom enum type, which was in my business project. In my service project, I had my data model project referenced but not the business project. So adding a reference to the model AND business project allowed me to add scaffold controllers fine.

    Seems obvious I know, but the error message it gives you is so unhelpful!

    Anyway, I hope this helps anyone having the same problem, and can't fix it using the other suggestions.

提交回复
热议问题