views:

274

answers:

1

Hello Overflow,

I am new to Windows Workflow [WF], and interested in evaluating WF for business purposes. I decided to work through an introduction

[TestMethod]
public void TestMethod ()
{
    TextWriter writer = new StringWriter ();
    Sequence sequence = new Sequence
    {
        Activities =
        {
            // so, assigning a reference type [eg StringWriter]
            // as target is prohibited in WF4RC. what or how do
            // i assign a target? introduction cited above may
            // not be current [ie may be Beta2, not RC] so ... ?
            new WriteLine { Text = "Hello", TextWriter = writer },
            new WriteLine { Text = "World", TextWriter = writer }
        }
    };
    // !!! BLOWS UP !!!
    WorkflowInvoker.Invoke (sequence);
}

and encountered

Test method SomeTests.SomeTests.TestMethod threw exception: System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree: 'Literal': Literal only supports value types and the immutable type System.String. The type System.IO.TextWriter cannot be used as a literal.

Poking around, I found this article describing what appears to be the error I see above.

Being new to WF, I do not really understand the change or proscribed method to work around it. So, my question is,

With WF4RC, how does one [correctly] use WriteLine activity?

+1  A: 

Ack, k, so mental note: Attempt all permutations of a Google search. Found this after searching for

WriteLine activity WF RC

The solution is to wrap it in a LambdaValue<T>, comme ca

[TestMethod]
public void TestMethod ()
{
    StringWriter writer = new StringWriter ();
    Sequence sequence = new Sequence
    {
        Activities =
        {
            new WriteLine 
            {
                Text = "Hello", 
                TextWriter = new LambdaValue<TextWriter> (n => writer) 
            },
            new WriteLine 
            {
                Text = "World", 
                TextWriter = new LambdaValue<TextWriter> (n => writer) 
            }
        }
    };
    WorkflowInvoker.Invoke (sequence);
    Assert.
        AreEqual (
        "Hello\r\nWorld\r\n", 
        writer.GetStringBuilder ().ToString ());
}

which seems weird to me, but I am literally the opposite of "expert" :P

I would still welcome alternatives if anyone has them.

johnny g