MetadataContainer: An element with the same key already exists

Thread is closed for posting
3 posts, 0 answers
  1. Markus
    Markus avatar
    43 posts
    Member since:
    Sep 2008

    Posted 12 Jan 2016 Link to this post


    I am trying to migrate my project to OpenAccess 2015.3 and fluent mapping. When to load data e.g. GetAll an ArgumentException is thrown:


    An element with the same key already exists in the Dictionary

       bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       bei System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       bei System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
       bei OpenAccessRuntime.DataObjectsRootBuilder.CreateFieldExtension(DataObjectsClass dataObjectsClass, List`1 fields, Dictionary`2 nameElementMap, MetaMember member)
       bei OpenAccessRuntime.DataObjectsRootBuilder.CreateFieldExtensions(DataObjectsClass dataObjectsClass, MetaType pcType)
       bei OpenAccessRuntime.DataObjectsRootBuilder.FromMetadataContainer(MetadataContainer metadataContainer)
       bei OpenAccessRuntime.DatabaseAdapter.AssertPersistenceManagerFactory(String usr, String password, Boolean open)
       bei OpenAccessRuntime.DatabaseAdapter.GetObjectScope(TransactionProvider provider)
       bei Telerik.OpenAccess.Database.GetObjectScope(TransactionProvider provider)
       bei Telerik.OpenAccess.OpenAccessContextBase.GetScope()
       bei Telerik.OpenAccess.OpenAccessContext.GetAllCore[T]()
       bei Telerik.OpenAccess.OpenAccessContext.GetAll[T]()


    I guess I have duplicate meta data configurations. But how to out which class? I tried to activate logging but with no result.




  2. Markus
    Markus avatar
    43 posts
    Member since:
    Sep 2008

    Posted 13 Jan 2016 in reply to Markus Link to this post

    Problem solved!

    Wrote my own tool to find duplicate field mappings:


    MyMetadataSource metaDataSource = new MyMetadataSource();
    Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer = metaDataSource.GetModel();
    foreach( Telerik.OpenAccess.Metadata.MetaPersistentType metaPersistentType in metadataContainer.PersistentTypes )
        IDictionary<string, string> typeMemberDict = new Dictionary<string,string>();
        foreach( Telerik.OpenAccess.Metadata.MetaMember metaMember in metaPersistentType.Members )
             if( typeMemberDict.ContainsKey(metaMember.Name) == false )
                  typeMemberDict.Add(metaMember.Name, metaMember.Name);
                  Console.WriteLine("Doppeltes Feld: " + metaPersistentType.Name     "." +  metaMember.Name);    

  3. Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 15 Jan 2016 Link to this post

    Hello Markus,

    That is the easiest way to detect the duplicates. 

    In case you need any further assistance do not hesitate to get back to us. 

    Kaloyan Nikolov
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top