Tuesday, April 6, 2010

Entity Framework Error 0019

I’ve got this error while refactoring a project that contains an Entity Data Model.  I’ve tried to google and find good solution.  Here it is:

image

Errors:

BAModel.csdl(3,4) : error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'BAEntities' is already defined.
BAModel.csdl(118,4) : error 0019: Each type name in a schema must be unique. Type name 'BAModel.Activity' was already defined.

One reason you might see this is if you have two models in a project that have the same schema. Maybe you decided to start your model over from scratch.

But in this scenario, that was not the case. It turned out that the problem was because I had changed the assembly name of the project that contained the model. The reference to the original assembly was still in the client application's BIN folder along with the new one.

image

Entity Framework was attempting to load the metadata files from both assemblies and detected the conflict.

Cleaning the project didn't fix the problem. The leftover assembly was still there.. I had to delete the dll and pdb file manually.

I first came across this problem and fixed it last week. But it happened again with another solution today and took me a while to remember the cause and the fix. The older I get, the more I need to rely on my blog for retaining that which my memory seems to be incapable of storing away.

Original solution

7 comments:

Anonymous said...

Really really mean issue... Been searching for the problem for about an hour already. :(

Your post helped, thank you! :)

Unknown said...

A bit late reply, but I'm really happy to help.

Gamesha said...

you saved hours of time for me, thanks a lot.

Unknown said...

nice to hear :)

Unknown said...

Thank you so much. That help me much

Unknown said...

Thank you so much. That help me much

Unknown said...

Thanks you very much for your post. I had a similar issue, and by cleaning up my bin files and recompiling. I was able to get my build to successfully remove the dangling references after clean up.