none
Right Click in Workflow Designer throws ArgumentException error An item with same key has already

    Question

  • I know how to fix this error but am asking if Workflow Designer should prevent this error.  

    Reproduce like this.  Drag two WriteLine activities onto blank designer and View XAML code.  Designer automatically creates unique IdRef values of "WriteLine_1" and "WriteLine_2"

        <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1"
        <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_2" 

    Now create CustomWriteLine activity using WriteLine activity (or any other).  I add an Inargument to pass it the value to write.  Build and close CustomWriteLine activity so that it is added to ToolBox.  Now drag two instances of CustomerWriteLine to the design surface.  Build again.  Now right click to get context menu and you will get ArgumentException error instead.

    Problem is that designer does not assign unique IdRef to each instance of custom activity.

    Is the designer suppose to work this way and so require editing of the XAML for every use of a custom activity?

    <Activity mc:Ignorable="sap sap2010 sads" x:Class="rightclickadddf" sap2010:WorkflowViewState.IdRef="rightclickadddf_1"
     xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
     xmlns:local="clr-namespace:MassMutual"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
     xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
     xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
     xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
     xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <TextExpression.NamespacesForImplementation>
        <sco:Collection x:TypeArguments="x:String">
          <x:String>System</x:String>
          <x:String>System.Collections.Generic</x:String>
          <x:String>System.Data</x:String>
          <x:String>System.Linq</x:String>
          <x:String>System.Text</x:String>
          <x:String>System.Activities</x:String>
        </sco:Collection>
      </TextExpression.NamespacesForImplementation>
      <TextExpression.ReferencesForImplementation>
        <sco:Collection x:TypeArguments="AssemblyReference">
          <AssemblyReference>mscorlib</AssemblyReference>
          <AssemblyReference>System</AssemblyReference>
          <AssemblyReference>System.Core</AssemblyReference>
          <AssemblyReference>System.Data</AssemblyReference>
          <AssemblyReference>System.ServiceModel</AssemblyReference>
          <AssemblyReference>System.Xml</AssemblyReference>
          <AssemblyReference>System.Activities</AssemblyReference>
        </sco:Collection>
      </TextExpression.ReferencesForImplementation>
      <Sequence DisplayName="Add DF Fields" sap2010:WorkflowViewState.IdRef="Sequence_6">
        <Sequence.Variables>
          <Variable x:TypeArguments="x:Boolean" Name="Success" />
        </Sequence.Variables>
        <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1" Text="Standard One" />
        <WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_2" Text="Standard Two" />
        <local:CustomerWriteLineActivity sap2010:WorkflowViewState.IdRef="CustomerWriteLineActivity_1" Text_In="Custom1">
          <sap2010:WorkflowViewState.ViewStateManager>
            <sap2010:ViewStateManager>
              <sap2010:ViewStateData Id="WriteLine_1" sap2010:WorkflowViewState.IdRef="ViewStateData_1" />
              <sap2010:ViewStateData Id="Sequence_1" sap2010:WorkflowViewState.IdRef="ViewStateData_2" />
              <sap2010:ViewStateData Id="CustomerWriteLineActivity_1" sap2010:WorkflowViewState.IdRef="ViewStateData_3" />
            </sap2010:ViewStateManager>
          </sap2010:WorkflowViewState.ViewStateManager>
        </local:CustomerWriteLineActivity>
        <local:CustomerWriteLineActivity sap2010:WorkflowViewState.IdRef="CustomerWriteLineActivity_1" Text_In="Custom2">
          <sap2010:WorkflowViewState.ViewStateManager>
            <sap2010:ViewStateManager>
              <sap2010:ViewStateData Id="WriteLine_1" sap2010:WorkflowViewState.IdRef="ViewStateData_4" />
              <sap2010:ViewStateData Id="Sequence_1" sap2010:WorkflowViewState.IdRef="ViewStateData_5" />
              <sap2010:ViewStateData Id="CustomerWriteLineActivity_1" sap2010:WorkflowViewState.IdRef="ViewStateData_6" />
            </sap2010:ViewStateManager>
          </sap2010:WorkflowViewState.ViewStateManager>
        </local:CustomerWriteLineActivity>
        <sads:DebugSymbol.Symbol>d2JDOlxEZXZlbG9wbWVudFxKaWdzYXdEYXRhXFByb2plY3RzXERhdGFGcmVlZG9tXFJlc2VhcmNoXFRlc3RWUzIwMTJcTWFzc011dHVhbFxyaWdodGNsaWNrYWRkZGYueGFtbAkgAzkOAgEBJAUkVAIBCCUFJVQCAQYmBS4nAgEELwU3JwIBAiRDJFECAQklQyVRAgEHJmwmdQIBBS9sL3UCAQM=</sads:DebugSymbol.Symbol>
      </Sequence>
      <sap2010:WorkflowViewState.ViewStateManager>
        <sap2010:ViewStateManager>
          <sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="211,61" />
          <sap2010:ViewStateData Id="WriteLine_2" sap:VirtualizedContainerService.HintSize="211,61" />
          <sap2010:ViewStateData Id="ViewStateData_1" sap:VirtualizedContainerService.HintSize="211,61" />
          <sap2010:ViewStateData Id="ViewStateData_2" sap:VirtualizedContainerService.HintSize="233,185">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="ViewStateData_3" sap:VirtualizedContainerService.HintSize="273,265" />
          <sap2010:ViewStateData Id="CustomerWriteLineActivity_1" sap:VirtualizedContainerService.HintSize="211,22" />
          <sap2010:ViewStateData Id="ViewStateData_4" sap:VirtualizedContainerService.HintSize="211,61" />
          <sap2010:ViewStateData Id="ViewStateData_5" sap:VirtualizedContainerService.HintSize="233,185">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="ViewStateData_6" sap:VirtualizedContainerService.HintSize="273,265" />
          <sap2010:ViewStateData Id="Sequence_6" sap:VirtualizedContainerService.HintSize="233,410">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="rightclickadddf_1" sap:VirtualizedContainerService.HintSize="273,490" />
        </sap2010:ViewStateManager>
      </sap2010:WorkflowViewState.ViewStateManager>
    </Activity>


    Wednesday, December 05, 2012 1:33 AM

All replies

  • I'm very much interested in knowing an answer to this too. Anyone have any thoughts?
    Wednesday, December 12, 2012 7:29 PM
  • I tried to reproduce the issue that you are reporting, but unfortunately was not able to. I used Visual Studio 2012 (Version 11.0.50727.1 RTMREL) with .NET 4.5 (Version 4.5.50709). What is the version that you are using?

    Thank you,

    Hani

    Friday, January 04, 2013 12:56 AM
  • I too am experiencing this issue which appears to have started when updating to VS2012 (from 2010).  Is there any way to come to know which item/key is causing the ArgumentException.  In this way perhaps one could manually change it to avoid the issue.

    I should include the fact that I attempted to attach the debugger of another instance of VS2012 to the instance viewing the WF to no avail.  The debugger did not catch the exception despite the fact that I told it to "stop when thrown".

    Thanks in advance!

    Chris


    • Edited by RosaKnowza Friday, March 01, 2013 1:37 PM Forgot some useful information
    Friday, March 01, 2013 1:35 PM
  • This fixes it:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Xml;
    using System.Xml.Linq;
    
    namespace XmlIdReindexer
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private Dictionary<string, List<XAttribute>> keys = new Dictionary<string, List<XAttribute>>();
    
            private void button2_Click(object sender, EventArgs evt)
            {
                if (openFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    var file = openFileDialog1.FileName;
    
                    XDocument doc = null;
    
                    using (var f = File.Open(file, FileMode.Open))
                    {
                        doc = XDocument.Load(f);
    
                        var attribs = from e in doc.Descendants()
                                      from a in e.Attributes()
                                      where a.Name == XName.Get("WorkflowViewState.IdRef", "http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation")
                                      select a;
    
                        foreach (var a in attribs)
                        {
                            List<XAttribute> l = null;
    
                            if (keys.TryGetValue(a.Value, out l) == false)
                            {
                                l = keys[a.Value] = new List<XAttribute>();
                            }
    
                            l.Add(a);
                        }
    
                        var q = from k in keys
                                where k.Value.Count > 1
                                select k;
    
                        listBox1.Items.Clear();
    
                        foreach (var key in q)
                        {
                            listBox1.Items.Add(key.Key);
    
                            Debug.WriteLine(key.Key);
    
                            int i = 0;
    
                            foreach (var item in key.Value)
                            {
                                item.Value = item.Value + (i++).ToString();
                            }
                        }
    
                        f.Close();
                    }
    
                    doc.Save(file);
                };
            }
        }
    }
    

    Friday, March 01, 2013 10:00 PM
  • For those looking for a fix to this, it's been fixed by MS finally via the following hotfix for VS.Net 2012...

    http://support.microsoft.com/kb/2828841

    Friday, April 26, 2013 4:50 PM