title: An item with the same key has already been added error in ASP.NET MVC 5
body: <p>I'm upgrading an ASP.NET MVC 3 project to MVC 5 (VS 2017) and i have the below line of code</p>
  
  <pre><code> IEnumerable&lt;Country&gt; countrydata = _db.Country.OrderBy(s =&gt; s.CountryName).ToList();
  </code></pre>
  
  <p>That line of code works fine in MVC 3 (in a .NET 4 project) but throws the below error in MVC 5 project targeting .NET 4.6.1, does anybody see why?</p>
  
  <blockquote>
    <p>An item with the same key has already been added</p>
  </blockquote>
  
  <p><strong>UPDATE:</strong>
  After further testing, it seems like all such calls to the database will fail in MVC 5 / Entity Framework 6, because even the below line fails with the same error message.</p>
  
  <pre><code>IEnumerable&lt;AuthenticationType&gt; authenticationProvider = _db.AuthenticationType.OrderBy(n =&gt; uthenticationProvider).ToList();
  </code></pre>
  
  <p>@Christos, see the .edmx designer message i mention below</p>
  
  <p><a href="https://i.stack.imgur.com/HMS8T.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HMS8T.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Below is the stack trace</strong></p>
  
  <blockquote>
    <p>at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary<code>2.Insert(TKey key, TValue value, Boolean add) at System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.LoadRelationshipTypes() at System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.LoadTypesFromAssembly() at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() at System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.Load() at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action</code>1 logLoadMessage, Object&amp; loaderCookie, Dictionary<code>2&amp; typesInLoading, List</code>1&amp; errors) at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection) at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly) at System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType) at System.Data.Objects.ObjectContext.GetEntitySetForNameAndType(String entitySetName, Type entityCLRType, String exceptionParameterName) at System.Data.Objects.ObjectContext.CreateObjectSet[TEntity](String entitySetName) at SSAMapper.Models.SSAMapperEntities.get_Country() in D:\Projects\SSAMapper\Models\SSAMapper.Designer.cs:line 240 at SSAMapper.Models.AdminModel.GetCountries(Boolean status, Boolean userCountry, Boolean loadDeactivatedCountry) in D:\Projects\SSAMapper\Models\AdminModel.cs:line 1116</p>
  </blockquote>