locked
InvokeMethod Activity to Call Clear Instance Method on a LinkedList(Of T) RRS feed

  • Question

  • I have a LinkedList(Of Bool) instance with name StakeholderVoteTally and I am trying to call Clear method of LinkedList using InvokeMethod Activity. I set TargetType to (null), TargetObject to StakeholderVoteTally, and MethodName to "Clear" on the designer surface of InvokeMethod Activity. I keep getting a red exclamation mark on the Activity with the following error: 'LinkedList`1' does not have a public instance method named '"Clear"' matching the parameter types, generic type arguments, and generic type constraints supplied to InvokeMethod 'Clear Stakeholder Response Tally'. There is an instance method Clear for LinkedList(Of T).

    I am missing something very subtle here, can anyone help?

    Friday, April 20, 2012 8:28 PM

Answers

  • Hi,

    It seems your steps are correct. Could you please post the code your xaml file here? The following  workflow about clear LinkedList(of T) by using InvokeMethod does work for me:

    <Activity mc:Ignorable="sads sap" x:Class="WorkflowConsoleApplication1.Workflow1" sap:VirtualizedContainerService.HintSize="353.6,1000" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation"
     xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System"
     xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
     xmlns:s="clr-namespace:System;assembly=mscorlib"
     xmlns:s1="clr-namespace:System;assembly=System"
     xmlns:s2="clr-namespace:System;assembly=System.Xml"
     xmlns:s3="clr-namespace:System;assembly=System.Core"
     xmlns:s4="clr-namespace:System;assembly=System.ServiceModel"
     xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities"
     xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
     xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
     xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
     xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System"
     xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel"
     xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core"
     xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib"
     xmlns:sd="clr-namespace:System.Data;assembly=System.Data"
     xmlns:sl="clr-namespace:System.Linq;assembly=System.Core"
     xmlns:st="clr-namespace:System.Text;assembly=mscorlib"
     xmlns:w="clr-namespace:WorkflowConsoleApplication21"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Sequence  sap:VirtualizedContainerService.HintSize="313.6,960">
        <Sequence.Variables>
          <Variable x:TypeArguments="scg:LinkedList(x:Boolean)" Default="[New LinkedList(Of Boolean)(New Boolean() {False, True, False, False})]" Name="StakeholderVoteTally" />
        </Sequence.Variables>
        <sap:WorkflowViewStateService.ViewState>
          <scg3:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
          </scg3:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <ForEach x:TypeArguments="x:Boolean" DisplayName="ForEach&lt;Boolean&gt;" sap:VirtualizedContainerService.HintSize="291.2,208" Values="[StakeholderVoteTally]">
          <ActivityAction x:TypeArguments="x:Boolean">
            <ActivityAction.Argument>
              <DelegateInArgument x:TypeArguments="x:Boolean" Name="item" />
            </ActivityAction.Argument>
            <WriteLine sap:VirtualizedContainerService.HintSize="214.4,62.4" Text="[item.ToString()]" />
          </ActivityAction>
        </ForEach>
        <WriteLine sap:VirtualizedContainerService.HintSize="291.2,62.4" Text="Clear start" />
        <InvokeMethod sap:VirtualizedContainerService.HintSize="291.2,134.4" MethodName="Clear">
          <InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="scg:LinkedList(x:Boolean)">[StakeholderVoteTally]</InArgument>
          </InvokeMethod.TargetObject>
        </InvokeMethod>
        <WriteLine sap:VirtualizedContainerService.HintSize="291.2,62.4" Text="Clear end" />
        <ForEach x:TypeArguments="x:Boolean" DisplayName="ForEach&lt;Boolean&gt;" sap:VirtualizedContainerService.HintSize="291.2,208" Values="[StakeholderVoteTally]">
          <ActivityAction x:TypeArguments="x:Boolean">
            <ActivityAction.Argument>
              <DelegateInArgument x:TypeArguments="x:Boolean" Name="item" />
            </ActivityAction.Argument>
            <WriteLine sap:VirtualizedContainerService.HintSize="214.4,62.4" Text="[item.ToString()]" />
          </ActivityAction>
        </ForEach>
      </Sequence>
    </Activity>


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 23, 2012 8:17 AM

All replies

  • I found out that I could easily clear the LinkedList(Of T) using ClearCollection<T> Activity but my original question remains such that why can I not call Clear method using InvokeMethod Activity on the LinkedList(Of T)?

    Friday, April 20, 2012 10:34 PM
  • Hi,

    It seems your steps are correct. Could you please post the code your xaml file here? The following  workflow about clear LinkedList(of T) by using InvokeMethod does work for me:

    <Activity mc:Ignorable="sads sap" x:Class="WorkflowConsoleApplication1.Workflow1" sap:VirtualizedContainerService.HintSize="353.6,1000" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation"
     xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System"
     xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
     xmlns:s="clr-namespace:System;assembly=mscorlib"
     xmlns:s1="clr-namespace:System;assembly=System"
     xmlns:s2="clr-namespace:System;assembly=System.Xml"
     xmlns:s3="clr-namespace:System;assembly=System.Core"
     xmlns:s4="clr-namespace:System;assembly=System.ServiceModel"
     xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities"
     xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
     xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
     xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
     xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System"
     xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel"
     xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core"
     xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib"
     xmlns:sd="clr-namespace:System.Data;assembly=System.Data"
     xmlns:sl="clr-namespace:System.Linq;assembly=System.Core"
     xmlns:st="clr-namespace:System.Text;assembly=mscorlib"
     xmlns:w="clr-namespace:WorkflowConsoleApplication21"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Sequence  sap:VirtualizedContainerService.HintSize="313.6,960">
        <Sequence.Variables>
          <Variable x:TypeArguments="scg:LinkedList(x:Boolean)" Default="[New LinkedList(Of Boolean)(New Boolean() {False, True, False, False})]" Name="StakeholderVoteTally" />
        </Sequence.Variables>
        <sap:WorkflowViewStateService.ViewState>
          <scg3:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
          </scg3:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <ForEach x:TypeArguments="x:Boolean" DisplayName="ForEach&lt;Boolean&gt;" sap:VirtualizedContainerService.HintSize="291.2,208" Values="[StakeholderVoteTally]">
          <ActivityAction x:TypeArguments="x:Boolean">
            <ActivityAction.Argument>
              <DelegateInArgument x:TypeArguments="x:Boolean" Name="item" />
            </ActivityAction.Argument>
            <WriteLine sap:VirtualizedContainerService.HintSize="214.4,62.4" Text="[item.ToString()]" />
          </ActivityAction>
        </ForEach>
        <WriteLine sap:VirtualizedContainerService.HintSize="291.2,62.4" Text="Clear start" />
        <InvokeMethod sap:VirtualizedContainerService.HintSize="291.2,134.4" MethodName="Clear">
          <InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="scg:LinkedList(x:Boolean)">[StakeholderVoteTally]</InArgument>
          </InvokeMethod.TargetObject>
        </InvokeMethod>
        <WriteLine sap:VirtualizedContainerService.HintSize="291.2,62.4" Text="Clear end" />
        <ForEach x:TypeArguments="x:Boolean" DisplayName="ForEach&lt;Boolean&gt;" sap:VirtualizedContainerService.HintSize="291.2,208" Values="[StakeholderVoteTally]">
          <ActivityAction x:TypeArguments="x:Boolean">
            <ActivityAction.Argument>
              <DelegateInArgument x:TypeArguments="x:Boolean" Name="item" />
            </ActivityAction.Argument>
            <WriteLine sap:VirtualizedContainerService.HintSize="214.4,62.4" Text="[item.ToString()]" />
          </ActivityAction>
        </ForEach>
      </Sequence>
    </Activity>


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 23, 2012 8:17 AM
  • Hi Leo,

    Thank you for the response, I tried again and now it works just fine, truly mind boggling why it just did not work last time. I could call 'Clear', 'AddLast' and pretty much all the instance methods exposed by LinkedList(Of T) through InvokeMethod Activity without a problem now. The only reason I can think of is that my workflow somehow "shadowed" the default type of LinkedList(Of T) but that should be impossible, or the workflow designer somehow lost track of the type information for LinkedList(Of T) for that particular workflow editing session.

    Tuesday, April 24, 2012 6:45 PM