none
An item with the same key has already been added. RRS feed

  • Question

  • We have a Silverlight 4 RIA that has been working great.  Per our regulations, we are forced to upgrade to VS 2010 SP1.  After applying it, we are getting the following exception every time we run our application. 

    {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.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
       at System.ServiceModel.DomainServices.Client.MetaType..ctor(Type type)
       at System.ServiceModel.DomainServices.Client.MetaType.GetMetaType(Type type)
       at System.ServiceModel.DomainServices.Client.Entity.get_MetaType()
       at System.ServiceModel.DomainServices.Client.Entity.RaiseDataMemberChanged(String propertyName)
       at xxxxxxx.Silverlight.Web.Models.organization_node.set_create_dttm(DateTime value)
       at Readorganization_nodeFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadArrayOfanyTypeFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
       at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
       at ReadQueryResultOfprojectFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
       at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
       at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
       at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
       at System.ServiceModel.Dispatcher.CompositeClientFormatter.DeserializeReply(Message message, Object[] parameters)
       at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeEndService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    This is thrown every time a value is set on a public property in one of the RIA Entity objects.  The error will throw when ValidateProperty or RaiseDataMemberChanged is called as part of the setter for the property.  I have tried a bunch of work arounds with no success.  I have upgraded to Visual Studio 2012, upgraded project to Silverlight 5, upgraded our 3rd party controls, nothing works.  I have Googled this and many others have had similar problems, but no solutions have been helpful.

    The call we are using to load our entities:

                context.Load<project>(context.GetProjectByProjectIdQuery(projectId), delegate(LoadOperation<project> operation)
                {
                    project currentProject = operation.Entities.First();
                    CurrentProject = currentProject;

                    CurrentProject.proj_stat_cd = ProjectStatus.Active.GetAttributeValue<CodeValueAttribute, string>();

                    callback.Invoke(currentProject);

                    ExitBusy();
                }, null);

    It dies before it can get to the first line in the delegate.

    Monday, September 10, 2012 3:17 PM

Answers

  • In case anyone looks at this thread and wonders what the solution was...we had to rename one of our properties on a partial entity. 

    As I read on other threads, people had issues with "HasChanges"...well watch out for "ValidationErrors" as well.  Microsoft should post a listing of new properties/methods/functions when SP or releases are released so that if we, the consumers of their products and frameworks, find our code is broken from an upgrade, then we can search for these types of things in our code and save time and money searching for the needle in the haystack to fix!

    • Marked as answer by snupeaAmI Monday, October 8, 2012 5:22 PM
    Monday, October 8, 2012 5:22 PM

All replies

  • Hi SnupeaAmI,

    Welcome to the MSDN forum.

    Before you upgraded to Visual Studio 2010 SP1, which version of Visual Studio did you use? Visual Studio 2010 or Visual Studio 2008?

    Also, could you please let me know the specific line where exception thrown?

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, September 12, 2012 6:39 AM
  • Hi snupeaAml,

    I found a similar issue which has solved, please refer here. I hope it could help. : )

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, September 13, 2012 5:45 AM
    Moderator
  • Hi...

    We have been using Visual Studio 2010.  As long as we stay in Visual Studio 2010, the application runs fine.  The application just won't run in Visual Studio 2010 SP1 or Visual Studio 2012.  We get the same error in Visual Studio 2012 at the same place.

    The exception is happening on the "this.RaiseDataMemberChanged();" in the property during loading of the entity.  We can also get it to die on the "this.ValidateProperty();" when creating the entity.  Same exception in both cases.  We can look at the data and we do not see a duplicate data record that it is loading. 

    Friday, September 14, 2012 2:40 PM
  • Hi,

    Yes..I saw this post early on in our research.  We are not using any [Composition] attributes and we do not  have a function called 'has changes'.  It sounded like something we would have done, but we didn't.  :(

    Thanks for the help!

    Friday, September 14, 2012 2:42 PM
  • Hi snupeaAml,

    I' afraid I'm not familiar with Silverlight and WCF RIA Service. I suggest you to post in this forum: http://forums.silverlight.net/53.aspx

    There're more related experts there, you may get more help. Sorry for my little help. I hope the issue can resolved soon. : )

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 17, 2012 3:26 AM
    Moderator
  • In case anyone looks at this thread and wonders what the solution was...we had to rename one of our properties on a partial entity. 

    As I read on other threads, people had issues with "HasChanges"...well watch out for "ValidationErrors" as well.  Microsoft should post a listing of new properties/methods/functions when SP or releases are released so that if we, the consumers of their products and frameworks, find our code is broken from an upgrade, then we can search for these types of things in our code and save time and money searching for the needle in the haystack to fix!

    • Marked as answer by snupeaAmI Monday, October 8, 2012 5:22 PM
    Monday, October 8, 2012 5:22 PM