locked
Cannot access InArgument of my custom activity RRS feed

  • Question

  • I have a custom activity with activity designer and it has an InArgument InArgA. But the inner activities cannot access the argument. I  am getting error

    "{"The argument of type 'System.String' cannot be used.  Make sure that it is declared on an activity."}" 

    while trying to access the InArgA.

     

    string value = InArgA.Get<string>(context);

    Anyone knows why?

    Sunday, May 29, 2011 3:45 PM

Answers

  • Quick one...

     public class MyAct : CodeActivity
      {
        public InArgument<string> InArgA
        {
          get;
          set;
        }
     
    
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
          RuntimeArgument myArgument = new RuntimeArgument("InArgA", typeof(string), ArgumentDirection.In);
          metadata.Bind(this.InArgA, myArgument);
          metadata.AddArgument(myArgument);
        }
        …
      }
    

    This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Moski Laraty Monday, May 30, 2011 3:01 PM
    Sunday, May 29, 2011 4:30 PM
  • Before executing an activity, the workflow runtime obtains all of the information about the activity that it needs in order to maintain its execution. The workflow runtime gets this information during the execution of the CacheMetaData  method.

    The default implementation of CacheMetaData method provides the runtime with all of the public arguments, variables, and child activities exposed by the activity at the time it is executed; if the activity needs to give more information to the runtime than this (such as private members, or activities to be scheduled by the activity), this method can be overridden to provide it.

    Here's the info about CacheMetaData. http://blogs.msdn.com/b/flow/archive/2010/04/06/workflow-foundation-4-0-activity-data-model-ii.aspx


    This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Moski Laraty Monday, May 30, 2011 3:01 PM
    Sunday, May 29, 2011 3:55 PM

All replies

  • Before executing an activity, the workflow runtime obtains all of the information about the activity that it needs in order to maintain its execution. The workflow runtime gets this information during the execution of the CacheMetaData  method.

    The default implementation of CacheMetaData method provides the runtime with all of the public arguments, variables, and child activities exposed by the activity at the time it is executed; if the activity needs to give more information to the runtime than this (such as private members, or activities to be scheduled by the activity), this method can be overridden to provide it.

    Here's the info about CacheMetaData. http://blogs.msdn.com/b/flow/archive/2010/04/06/workflow-foundation-4-0-activity-data-model-ii.aspx


    This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Moski Laraty Monday, May 30, 2011 3:01 PM
    Sunday, May 29, 2011 3:55 PM
  • I'm new to WF, do you mind giving me an sample custom activity with a InArgument of string type? thanks!
    Sunday, May 29, 2011 4:09 PM
  • Quick one...

     public class MyAct : CodeActivity
      {
        public InArgument<string> InArgA
        {
          get;
          set;
        }
     
    
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
          RuntimeArgument myArgument = new RuntimeArgument("InArgA", typeof(string), ArgumentDirection.In);
          metadata.Bind(this.InArgA, myArgument);
          metadata.AddArgument(myArgument);
        }
        …
      }
    

    This posting is provided "AS IS" and confers no rights or warranties.
    • Marked as answer by Moski Laraty Monday, May 30, 2011 3:01 PM
    Sunday, May 29, 2011 4:30 PM
  • Thanks for sharing. Sorted my problem but I don't understand why this is occurring in a specific activity while all my other activities are working without having to bind it in the CacheMetadata method.

    Having said that, it is the first time that I'm creating an object using the AssignTo Activity and then in my activity, I'm assigning values to a collection contained in this object.

    Thanks again.

    Thierry

    Tuesday, March 28, 2017 2:57 PM