none
svcutil error: item with same key has already been added

    Question

  • I've been running svcutil for a while now, but for some reason am getting this error now. Does anyone know what would cause it or how to find out?

    svcutil.exe" /outTongue TiedymyxWorkflowService.cs /ctTongue Tiedymyx.Framework.Workflow.WorkflowDefinitionCollection /ct

    Tongue Tiedymyx.Framework.Workflow.WorkflowStageCollection /ctTongue Tiedymyx.Framework.Workflow.WorkflowEventCollection /ctTongue Tiedymyx.Framewo

    rk.Workflow.WorkflowInstanceCollection /r:".\..\..\Reference bin\Symyx.Framework.dll" http://localhost:8081/SymyxWorkflowService/MEX

    Microsoft (R) Service Model Metadata Tool

    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]

    Copyright (c) Microsoft Corporation. All rights reserved.

    Attempting to download metadata from 'http://localhost:8081/SymyxWorkflowService/MEX' using WS-Metadata Exchange or DISC

    O.

    Error: There was an error loading a referenced contract type. This type will be ignored.

    Type: Symyx.Framework.Vault.Proxy.VaultEventQueueService, Symyx.Framework, Version=1.0.0.0, Culture=neutral, PublicK

    eyToken=null

    An item with the same key has already been added.


    Monday, July 09, 2007 7:15 PM

All replies

  • Can you share us the contract? Is there any stack trace with the exception?

     

    Thanks, Dinesh.

    Tuesday, July 10, 2007 1:22 AM
    Moderator
  • I'm getting a similar problem.

    I run svcutil <serviceUri> /d:<myfolder> /r:<assembly1> /r:<assembly2>...

    with 4 assemblies.

    1. It fails with error "There was an error loading a referenced contract type.  This type will be ignored"...
    2. If I remove one of the /r assemblies, then it appears to succeed (no errors) but only generates an output.config file
    3. If I remove all the /r assemblies, it works fine, but is not what I need/want

    (I'm using Visual Studio 2008 SP1 on Vista Business x64 SP1)

    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Attempting to download metadata from 'net.tcp://localhost:8086/Service1/MEX' using WS-Metadata Exchange. This URL do
    es not support DISCO.
    Error: There was an error loading a referenced contract type. This type will be ignored.
        Type: <TypeNameHere>, <Namespace>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=125673412f1e4e59

        An item with the same key has already been added.

    Any ideas? thanks!

    I'm still trying to track down my original problem which is adding a service reference in Visual Studio doesn't work for me:

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/7b51455b-cdba-470c-8009-fdaebe2c9a64/

    - Alex
    • Edited by noirs Thursday, April 09, 2009 3:11 PM
    Thursday, April 09, 2009 1:53 AM
  • Could it be that you add assmbly which contains refrence to all other assemblies? In this case you'll get this error when svcutil will strat to process other assembly which already was processed.

    > 3. If I remove all the /r assemblies, it works fine, but is not what I need/want
    what do you mean, what you expect?

    Could you post configuration?
    Regards
    Thursday, April 09, 2009 12:26 PM
  • Hi Vlyaku,

    1. I'm not sure exactly what you mean..  There are references between the assemblies.

    2. I don't think I can post much more information, what specifically do you mean when you say "Configuration"?

    I worked more on this problem, and added an /excludeType:<TypeNameHere> to exclude that type, and then svcUtil completed without error, but it still didnt' generate a proxy file.  I Then added more arguments like /l:C# and /tvc etc and then it said no code was generated because no service contracts (etc) were found in the service that were not in the referenced files... which is true. But, I'd still like a proxy generated.

    I then figured out that I can actually do what I need to do without a proxy: http://blogs.msdn.com/diegobar/archive/2008/04/10/wcf-without-svcutil-tool.aspx

    And that makes life much easier!
    Thursday, April 09, 2009 3:05 PM
  • You could use ChannelFactory to call service, but you'll need service contract and data contracts. Also i'm not sure i understand what these assemblies for?

    > 3. If I remove all the /r assemblies, it works fine, but is not what I need/want
    what do you expect?

    Do you try to get some extra types from assemblies which will be included to service proxy?
    Regards
    Thursday, April 09, 2009 3:24 PM
  • 1. The reason I specify those assemblies is that they contain common types used by my service, and I'd prefer to use those types directly, rather than proxies.  For example, one of my types has a ToString method on it which is handy, the proxies don't.

    2. If I don't specify those assemblies, then svcutil does in fact generate a proxy, but the code it generated doesn't compile.  One of the classes is present twice, so the compiler complains that properties in that class are declared twice.

    (So I was mistaken when I said it 'works fine').
    Thursday, April 09, 2009 3:29 PM
  • About 1. This is the answer for your question - you get this error because you include types twice.
    About 2. yes, sometimes it happened... you could just remove dublications.

    In my personal opinion you should:

    Create service proxy using svcutil or VS. I assume you trying to add reference to local service so using VS it could be easy - just select Add Service Reference and you done. All types will be exported, not sure why you need to use assemblies directly - if you change something you could update service proxy, and this will be correct.
    or

    You could add refernces to your assemblies and use ChannelFactory to work with service etc... in this case i hope you have good enought solution hierarchy to do not include to much useless types ets...
    Regards
    Thursday, April 09, 2009 3:38 PM
  • 1. I don't include any types twice.

    I'm trying to use a feature of svcutil which is to reference types instead of generating proxies for them.

    2. Sure i could remove the duplicated generated class (its just one), but why doesn't the code that svcutil generates compile? If I remove them, this mean its a manual step I'd have to perform EVERY time I re-generate the proxies.

    In this scenario I am just executing this:

    svcutil net-tcp://localhost/myservice

    So its not clear to me why svcutil is generating broken code.

    Thursday, April 09, 2009 4:00 PM
  • I have no idea why svcutil could generate broken code also. That happened somtimes for me too, but as i remember when i'm updating service proxy - it generates "good" code, without dublications.
    Regards
    Friday, April 10, 2009 7:26 AM
  • Hi Steve,

    This happened to me but it was my own mistake, my problem was that I was trying to expose more than one endpoint for the same contract and I was applying the same behavior to both endpoints so when it went to apply the behavior to the second endpoint it was throwing the exception that you are experiencing.

    I fixed the problem by modifying the ApplyDispatchBehavior method to make sure that the behavior hadn't been already applied.

    Hope this helps.
    Abe
    Monday, April 27, 2009 2:43 PM