R – Windows Workflow Foundation 4.0 and Persistence

persistencewindowsworkflow-foundation-4

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");

Best Answer

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);