Exception on EntityFramework 5 dll version 4.0 RRS feed

  • Question

  • Hi,

    I have an application that's using EntityFramework 5.
    The dll version is 4.0 .
    I am getting an exception executing a console application that executes with Framework4.

    The application was working right, until today.
    At this moment I have the issue in two machines with Windows 7 and FX4 and FX4.5 installed.

    Probably some automatic updates generates the issue.
    I found a workaorund using the entity framework dll with version 4.4 ... but, it will force me to make tests and deployments with the new version.

    Anyone had this issue ? Maybe an idea how how to solve it using the dll version 4.0 ?
    Any ideas regarding what could cause that issue ?

    Here is the exception:

    The type initializer for 'System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions' threw an exception. 
    ---> System.ArgumentException: An item with the same key has already been added.
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions.IsValidStructuralType(Type type)
       at System.Data.Entity.Internal.DbSetDiscoveryService.GetSets()
       at System.Data.Entity.Internal.DbSetDiscoveryService.InitializeSets()
       at System.Data.Entity.DbContext..ctor(DbConnection existingConnection, Boolean contextOwnsConnection)
       at Itx.UofR.Health.Core.Model.HealthContext..ctor(DbConnection existingConnection, Boolean contextOwnsConnection) in Z:\xxx.Context.cs:line 22

    Monday, May 6, 2013 9:42 PM

All replies

  • Hi Pablo,

    Could you please post some code where this exception is generated?

    I can see the exception is "An item with the same key has already been added". Are you using Code First or Database First / Model First? We cannot find the real problem without any code here.

    Any updates will be appreciated?

    Best regards,

    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 8, 2013 7:59 AM
  • Hi Chester,

    I get the exception when I create an instance of the class SchoolEntities that inherits from  System.Data.Entity.DbContext class.            

    I am using Database First and TT files to generate POCO objects.

    This is a class that reproduce the issue.


        using System;
        using System.Data.Entity;

        public partial class SchoolEntities : DbContext
            public SchoolEntities()
                : base("name=SchoolEntities")

            public DbSet<Course> Courses { get; set; }

    I have one Windows 2003 Servers with FX4.0, without FX 4.5 where the application runs without issues.

    I have two Windows 7 Servers with FX4.0 and FX 4.5 installer where I am having the issue.

    Tks for your help!

    Wednesday, May 8, 2013 2:14 PM