0
votes

When creating a new web-api controller for certain entities I get the error 'An item with the same key has already been added'.

The weird thing is, that is works for some entities, but for some it doesn't. I couldn't find a pattern, really. My workflow is to: Rightclick folder, Add-> Controller. Select 'Web API 2 Controller with actions using Entity Framework'.

I use Visual Studio 2013 Update 4, EF 6.1.3 and Web API 2 5.2.3. What used to fix this error is to remove this line from my datacontext:

// OnModelCreating in MyContext.cs
modelBuilder.Configurations.AddFromAssembly(GetType().Assembly);

Commenting this line out and rebuilding used to solve the issue, but not anymore :(. Any ideas?

Error Message

Could you show us the rest of your OnModelCreating method. What else has been added? Any custom configuration/conventions etc. - phuzi
I removed everything, the problem persists. - LueTm