With the rc1 and rc2 the migration generate an error "An item with the same key has already been added", the problem is that the message not indicate the code which throw the exception.
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException (ExceptionResource resource) <0x7f064a680550 + 0x00021> in <filename unknown>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) <0x7f064a500a30 + 0x00168> in <filename unknown>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) <0x7f064a4ffbe0 + 0x0001b> in <filename unknown>:0
at Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator.Generate (Microsoft.Data.Entity.Migrations.Operations.CreateTableOperation operation, Microsoft.Data.Entity.Internal.IndentedStringBuilder builder) <0x423a9000 + 0x003c5> in <filename unknown>:0
at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator,object,Microsoft.Data.Entity.Internal.IndentedStringBuilder)
at Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator.Generate (System.String builderName, IReadOnlyList`1 operations, Microsoft.Data.Entity.Internal.IndentedStringBuilder builder) <0x42358cb0 + 0x001fc> in <filename unknown>:0
at Microsoft.Data.Entity.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration (System.String migrationNamespace, System.String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations) <0x42354f90 + 0x004c0> in <filename unknown>:0
at Microsoft.Data.Entity.Migrations.Design.MigrationsScaffolder.ScaffoldMigration (System.String migrationName, System.String rootNamespace, System.String subNamespace) <0x4231a670 + 0x006cf> in <filename unknown>:0
at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration (System.String name, System.String outputDir, System.String contextType) <0x42265e50 + 0x0011e> in <filename unknown>:0
at Microsoft.Data.Entity.Commands.Program+Executor+<>c__DisplayClass6_0.<AddMigration>b__0 () <0x41dd3840 + 0x00034> in <filename unknown>:0
at Microsoft.Data.Entity.Commands.Program+Executor.Execute (System.Action action) <0x41dd37b0 + 0x00028> in <filename unknown>:0
An item with the same key has already been added.
The entities are generated correctly with beta8.
But now apparently the migration implement automatically the discriminator in the whole of entities, that's what i see when execute an action with loading entities on the old table with a hierarchy. I use a base class with the common columns that is inherited by the others, and perhaps EF want to generate a table with the base class to respect the TPH and which will contain all entities by default, before only the entity with an explicit discriminator with the fluent api was generated and the other entities have the hierarchy into the table with the name of derived class.
An another issue to refer to this message #2170
@branciat Could you share your entity classes and DbContext class that cause this exception to be thrown?
Hummm... I have 79 classes and i don't know these that throw the exception :(
I will load the entity framework into visual studio 2015 and break the methods above.
Well, once loading the entity framework in the solution, i have a new exception in the EntityFramework.Commands
dnx.exe : System.TypeInitializationException: Une exception a ‚t‚ lev‚e par l'initialiseur de type pour 'Microsoft.Data.Entity.Commands.Program'. ---> System.IO.FileLoadException: Impossible de charger le fichier
ou l'assembly 'Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' ou une de ses d‚pendances. Un assembly avec un nom fort est requis. (Exception de
HRESULT : 0x80131044) ---> System.IO.FileLoadException: Un assembly avec un nom fort est requis. (Exception de HRESULT : 0x80131044)At line:1 char:1
+ dnx ef migrations add initial --context MediagralV2Entities
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (System.TypeInit...T : 0x80131044):String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
--- Fin de la trace de la pile d'exception interne ---
… Microsoft.Data.Entity.Commands.Program..cctor()
--- Fin de la trace de la pile d'exception interne ---
… Microsoft.Data.Entity.Commands.Program..ctor()
System.IO.FileLoadException: Impossible de charger le fichier ou l'assembly 'Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' ou une de ses d‚pendances.
Un assembly avec un nom fort est requis. (
Exception de HRESULT : 0x80131044)
Nom de fichierÿ: 'Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' ---> System.IO.FileLoadException: Un assembly avec un nom fort est requis. (Exception
de HRESULT : 0x80131044)
… Microsoft.Data.Entity.Commands.Program..cctor()
System.IO.FileLoadException: Un assembly avec un nom fort est requis. (Exception de HRESULT : 0x80131044)
The Microsoft.Extensions.PlatformAbstractions assembly or one dependencies required an assembly with a strong name.
How can i debug the program ? otherwise an archive which contain the entities and MediagralV2Entities that's the dbContext Entities
UPDATE
After a complete update of the whole package and a pull of entity framework, the exception not occurred
I deleted the hierarchies proceeding by step to detect an eventually intermediate error without success, now the migration no generate errors, but the entities are very ugly :(
Ok i find the entities which throw the exception, they are the entities of base class product and entity,
I don't declare of discriminator for these classes.
The exception is throw in Generate of CSharpMigrationOperationGenerator line 39
My latest migration with any error is 7.0.0-rc1-15945, i think it is just before that the migration verify the root in the declaration of discriminator.
Well, the exception occurred because i have the same property into two derived classes and the fluent api use an discriminator for the base class. Just added the entity name and the property name in the message that simplifying research.
Ah thanks, this may be a dupe of #3061
Oops, I was on the beta 8 for the test, after correction the error appear still on the rc1.
And also I have the error, describe above, on rc1 that seeks to apply the discriminator on all tables with base class without discriminator defined by the fluent api.
Yes, it's a dupe of #3061
The issue is closed but l don't see throw exception code in the command operation to know which table and column is already added, i tested with rc2. I find useful, right ?
I started the changes in the class because I need it, I can send you by modifcations pull request? if you are interested.
Oh sorry, I was closing it because it was a duplicate of #3061. #3061 will stay open until it's fixed.
In my case it was caused by duplicit IDbContextFactory
Most helpful comment
In my case it was caused by duplicit IDbContextFactory implementation (twice, in 2 different files).