32

I have a problem with an EDMX file which I've never encountered before. Seemingly randomly when the site is running or I'm debugging, the EF will bomb out and complain that everything is re-defined. I have to restart the app pool and re-attach the debugger every time, then start again from where I left off, after which it works again until the next time it bombs out.

I've already recreated the EDMX with a different name, hence MyAppEntities*1*

The error is:

Error: Schema specified is not valid. Errors: App_Code.Fck.csdl(3,4) : 
error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'MyAppEntities1' is already defined. App_Code.Fck.csdl(69,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.AdSection' was already defined. App_Code.Fck.csdl(79,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.AgeRating' was already defined. App_Code.Fck.csdl(89,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Comment' was already defined. App_Code.Fck.csdl(101,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.ContentImage' was already defined. App_Code.Fck.csdl(115,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.ContentVideo' was already defined. App_Code.Fck.csdl(126,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FeaturePlan' was already defined. App_Code.Fck.csdl(142,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Flick' was already defined. App_Code.Fck.csdl(165,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Gallery' was already defined. App_Code.Fck.csdl(184,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Genre' was already defined. App_Code.Fck.csdl(197,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Like' was already defined. App_Code.Fck.csdl(208,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Meta' was already defined. App_Code.Fck.csdl(216,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Payment' was already defined. App_Code.Fck.csdl(236,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.StatusUpdate' was already defined. App_Code.Fck.csdl(246,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.UserProfile' was already defined. App_Code.Fck.csdl(277,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_FeaturePlans_AdSections' was already defined. App_Code.Fck.csdl(289,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Flicks_AgeRatings' was already defined. App_Code.Fck.csdl(301,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Comments_Users' was already defined. App_Code.Fck.csdl(313,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Payments_FeaturePlans' was already defined. App_Code.Fck.csdl(325,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Flicks_Users' was already defined. App_Code.Fck.csdl(337,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Genres_Genres' was already defined. App_Code.Fck.csdl(349,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Likes_Users' was already defined. App_Code.Fck.csdl(361,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Payments_Users' was already defined. App_Code.Fck.csdl(373,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_StatusUpdates_Users' was already defined. App_Code.Fck.csdl(385,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FlickGenres' was already defined. App_Code.Fck.csdl(389,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.User' was already defined. App_Code.Fck.csdl(401,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Users_be_Users' was already defined. App_Code.Fck.csdl(413,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.ContentImageSet' was already defined. App_Code.Fck.csdl(426,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_ContentImages_ContentImageSets' was already defined.
Echilon
  • 10,064
  • 33
  • 131
  • 217
  • http://stackoverflow.com/questions/2060278/c-entity-framework-the-entitycontainer-name-must-be-unique-an-entitycontain – Damith Jul 24 '11 at 15:33

11 Answers11

56

You may be changed the assembly name of the project that contained the model.

The reference to the original assembly was still in the client application.

ASP.net Web Application : - Manually delete dll and pdb files.

ASP.net Web Site: - Perform an IIS reset then flush out the asp.net temporary files in the folder C:\windows\microsoft.net\your framework version\temp asp.net files\

Damith
  • 62,401
  • 13
  • 102
  • 153
  • This is a standard ASP.NET web site, not an application so there isn't a compiled bin directory. – Echilon Jul 24 '11 at 17:25
  • 2
    This solved my issue -- I deployed my dll to the GAC but forgot to delete it out of the bin directory – Barrett Aug 12 '11 at 22:03
  • 1
    To reset IIS run CMD in administrator mode and run "iisreset -restart". My temp asp files were in C:\Users\MyUsername\AppData\Local\Temp\Temporary ASP.NET Files – John Feb 28 '14 at 05:24
  • 3
    Yes, I had to clear out my bin folder. For me, I was getting this error when deploying to a server 2003 site. I had renamed a project, and the old assembly (.dll) was there. Since the connection string started with "res://*;...", it searched ALL assemblies (even non-loaded ones) for the resource and found duplicates (obviously). – James Wilkins Mar 12 '15 at 20:48
  • 5
    This is what does my head in completely about this kind of work. How the hell is anyone supposed to figure this kind of problem out without searching StackOverflow or wasting hours of time? I just hit this problem myself, and the disappointing truth is that the above answer was actually the solution. Huge thanks of course to Damith, but the mind boggles at what the alternative would have been had this answer not been here. – Sentinel Sep 11 '16 at 12:01
4

I had this same error. This is a problem about dlls, on my case was a duplicated dll.

Lücks
  • 3,806
  • 2
  • 40
  • 54
4

For Those who's problem is not yet resolved, try modifying the connection String in web.config.

In My Case I changed connectionString

From

<add name="StudentRegistrationDB" connectionString="metadata=res://*/App_Code.EFDataModel.StudentReg.csdl|res://*/App_Code.EFDataModel.StudentReg.ssdl|res://*/App_Code.EFDataModel.StudentReg.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=StudentRegistration;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

To:

 <add name="StudentRegistrationDB" connectionString="metadata=res://App_Code.EFDataModel2.StudentRegDB.csdl|res://App_Code.EFDataModel2.StudentRegDB.ssdl|res://App_Code.EFDataModel2.StudentRegDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=StudentRegistration;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

note that 'star' in metadata has been removed, so that meta data is pointed to absolute location. Because of 'star' EF is searching everywhere. Hence duplicates might be encountered

Note: This is a simple fix, which means you are not clearing any duplicate data, which is not a good idea. The best way is to delete duplicate .pdb/.dll files as suggested by previous answers.

Ganesh Vellanki
  • 412
  • 8
  • 18
3

I had the same problem with a diferent solution, i have a two projects using entity framework, with models of the same database with the same name, all the tables that had added on both models where on the inner exception message, the solution was to rename one of the models

Rafael
  • 2,642
  • 2
  • 24
  • 30
  • 1
    Incredibly, THIS is the solution that worked for me as well. I'm stunned. I have 2 project in the same solution that both named the model "EISContext". Runtime exceptions every time until I changed the name of the model in one of the projects to "BatchEISContext". – markaaronky Sep 22 '17 at 18:02
2

I have hit this problem whilst working on a process to allow assemblies for sub-applications to be loaded dynamically without requiring the whole app to be restarted. I am using EF 5.0 with DbContext. My workaround was to:

  1. Change the Entity Container Name so the it reflects the assembly version, e.g. CustomerEntities_1_0_7_0 and save the edmx.
  2. Manually amend the context to remove the version suffix:

    public partial class CustomersEntities : DbContext
    {
    public CustomersEntities() : base("name=CustomersEntities")
    
  3. Manually amend app.config likewise.

johndsamuels
  • 329
  • 1
  • 10
2

I just had that same problem. Entity Framework generated files CANNOT be in App_Code folder. I mean EDMX files.

I bet you had error that you wasn't able to reference files, so you checked property from Content to Compile. That solved VS error, but created double instances - precompiled one and runtime compiled.

Solution is to keep it away from App_code folder as it is special folder for code only.

Gumowy Kaczak
  • 1,457
  • 2
  • 16
  • 28
2

For my case, deleting the model and creating it with new name solved this issue

Yasser Amer
  • 111
  • 1
  • 2
2

I faced this exception recently and the solution to this problem is to delete an old DLL or duplicate DLL referenced in your solution Bin folder. This completely solved my problem.

Ricky
  • 488
  • 3
  • 14
  • In my situation, I moved a project into another solution and renamed the project. The dll for the old project name was never deleted in the bin folder. This caused the conflict. Removing the old project name dll from the bin fixed the issue. – ShawnOrr Dec 04 '20 at 15:37
1

After digging for 2 days finally I found the cause of the problem. I had 2 dll's (database application) which pointing to same entity framework database in the same project. In short it had duplicate dll's for one database. After removing irrelevant dll, it started working fine.

0

Clean, rebuild, deploy in release mode.

Kurkula
  • 6,386
  • 27
  • 127
  • 202
0

I finally solve my own problem and it was really nonsense. I just exclude (Exclude from project) folder which contain Model.edmx files

Amir
  • 1