views:

467

answers:

1

I'm using the Beta 2 version of Visual Studio 2010 to get a head start on learning to use WF4, and have run into a problem with persistence. In the code below, if I use the commented out creattion of a WorkflowApplication object, persistence works fine. If I use the un-commented creation below, where I pass a dictionary for arguments I want to pass in, then persistence breaks. Any ideas why this may be, and how to fix it?

        List<Approver> approversRequired = new List<Approver>();
        approversRequired.Add(new Approver("Dept Manager"));
        approversRequired.Add(new Approver("Center Manager"));

        Dictionary<String, Object> wfArguments = new Dictionary<string, object>();
        wfArguments.Add("ApproversRequired", approversRequired);

        //WorkflowApplication workflowApp = new WorkflowApplication(
        //    new WebCARSWorkflow());

        WorkflowApplication workflowApp = new WorkflowApplication(
            new WebCARSWorkflow(), wfArguments);

        InstanceStore instanceStore = new SqlWorkflowInstanceStore(
            @"Data Source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=WorkflowInstanceStore");
        InstanceView view = instanceStore.Execute(
            instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(),
            TimeSpan.FromSeconds(30));
        instanceStore.DefaultInstanceOwner = view.InstanceOwner;

        workflowApp.InstanceStore = instanceStore;

        workflowApp.PersistableIdle = (waie) => PersistableIdleAction.Unload;

        workflowApp.Run();
        WorkflowGuid.Text = workflowApp.Id.ToString();

        workflowApp.ResumeBookmark("RequestSubmitted", "Submitted");
+1  A: 

Is the Approver you pass in as a parameter decorated with the Serializable or the DataContract attribute?

You can see persitence errors using the Aborted callback

            workflowApp.Aborted = e => Console.WriteLine(e.Reason);
Maurice
I do have the class decorated with [Serializable], but do not know about DataContract, can you give me more information on that?
Russ Clark
DataContract is used with the WCF NetDataContractSerializer that WF4 uses by default to save the values to the database. This requires types to b serializable. There are two ways to do so, the easy using the Serializable attribute where all private fields are serialized. The other option is to use the DataContract attribute which gives full control over what needs to be serialized and how this is done.If there is a serialization error the WorklfowApplication.Aborted callback will give you the details.
Maurice