Comments (9)

  1. Notre says:

    Hi Tim,

    Thanks for this post.  The cache metadata seems a bit confusing to me.  Your post helps clarify some of the confusion, but I think it’ll take some trial and error on my part to completely understand the subtly.  

    It seems a bit strange to me that an activity can modify its implementation variables, but not its public variables.  I realize public variables are not ‘owned’ like implementation variables, but not being able to modify them seems strange.  How does an activity author initialize a public variable (or do they not)?

    Having to use a variable to initialize the argument seems a bit convoluted.  I take it your ‘bonus point’ is an alternate way to achieve this initialization without using a variable.  What kind of issues would we see if we used this approach in terms of ’round tripping to XAML’?

    Finally, I noticed that the override to CacheMetadata calls the base class’ CacheMetadata method.  I was under the impression from the earlier post that this wasn’t a good idea, for performance reasons.  Is it necessary to call the base class method for some reason, in this example?



  2. tilovell09 says:

    Public variables cannot be modified directly using context.SetValue(), but they can be

    -initialized to a default value based on an expression

    -passed to a public child which initializes them using an OutArgument (such as Activity<T> – or Assign)

    Calling base.CacheMetadata() – it’s an easy way to initailize the metadata needed for argument Duration.

  3. tRex says:

    Hi Tim

    I have a problem related to this post and cant believe that its not easy to implement. I've created a composite activity using the activity.xaml template. It contains a ForEach and a nested If. Im trying to expose the If Condition up into the activity designer but cant seem to grasp it. I suspect CacheMetadata should be used in a code beside class? Am I close to the answer, is this possible?



  4. tilovell09 says:

    Hi TRex,

    I'm not really sure whether what you want to do is possible or not.

    For a composite activity, like you generate by creating a Workflow1.xaml file, it is possible to override CacheMetadata in code-beside file. The main reason I can think of is to add validation logic. But I don't think overriding Activity.CacheMetadata helps. ActivityMetadata limits what you can do, compared to NativeActivityMetadata, and I don't think it gives you any extra wiggle room,

    My gut feeling is that overriding Activity.CacheMetadata is a dead end because either what you want to do is possible without overriding Activity.CacheMetadata, or it is just impossible (or requires being a NativeActivity is another possibility…)


  5. riezebosch says:

    It appears to me that the inner activity has to be a property, public or private whatsoever. When I it is a private member, I got the same error telling that variables could not be found in given scope….

  6. tilovell09 says:


    That is due to the behavior of base.CacheMetadata(), which I am calling in all my code [but you don't have to call it, if it doesn't do what you want]. Calling base.CacheMetadata gives you a 'default' cached metadata based on the public properties of your (current) activity. If you have a property 'public Activity Child { get; set; } then base.CacheMetadata automatically calls metadata.AddChild(). If your property were private you could achieve the same affect by calling metadata.AddChild() yourself, after calling base.CacheMetadata. (Note, if your property is private, when building a designer for your activity, you also won't see it in your model item's model properties.)


  7. Notre says:

    Your blog post just helped me out (after reading it many months ago) – thanks!…/d01d446c-56d9-4f2b-a22b-03c782f70596

  8. Notre says:

    Hi Tim,

    Your blog post did help me out a lot, but now I've run into a snag for which I hope I can get your expertise.  Please see WF question:…/fa6bb712-c911-4c81-b215-2300c031d6f2

    I just updated the WF forum question with what I think is a simple repro scenario.

    Thank you!

  9. Bob says:

    4 Years down the line & this blog entry is still helping people – thanks soooo much!

Skip to main content