1
votes

I've been plagued by an error with resuming workflows in a rather complex system and so far had very little luck finding a solution to it.

The error happens when I resume a workflow. The workflow and the activities have changed but there is versioning in place that shouldn't affect that. The resume operation brings out the old version of the xaml file and calls the old version of those activities and that has been working well for a year now.

Started testing a new version of the system and suddenly I get this error: The instance 'some guid' was found in the instance store, but the instance is not a workflow instance

This happens in the Resume method of worklfow and in particular in this line :

application.Load(resumeContext.WorkflowInstanceId);

In the database I can find the instance with that Guid and it looks okay so I can't understand why it wouldn't load.

I found only one page in the entire google with this error and there's no answer to it, so it's the desert out there.

The stack trace is useless:

Exception: System.Exception: Exception of type 'System.Exception' was thrown.

   at System.Activities.WorkflowApplication.ExtractRuntimeState(IDictionary`2 values, Guid instanceId)
   at System.Activities.WorkflowApplication.ProcessInstanceValues(IDictionary`2 values, Object& deserializedRuntimeState)
   at System.Activities.WorkflowApplication.LoadCore(DynamicUpdateMap updateMap, TimeoutHelper timeoutHelper, Boolean loadAny, IDictionary`2 values)
   at System.Activities.WorkflowApplication.Load(Guid instanceId, TimeSpan timeout)
   at System.Activities.WorkflowApplication.Load(Guid instanceId)
   at Project.TS.Services.Workflows.Hosting.ActivityInvoker.Resume[TResponse](WorkflowApplication application, InstanceStore instanceStore, ResumeBookmarkContext`1 resumeContext, IDictionary`2& outArguments) 
   in c:\Projects\TS\trunk\Services\Workflows\Hosting\ActivityInvoker.cs:line 186

Some more info. The way it works is the operation object contains the workflow version, name and actual Xaml and this gets loaded into a workflow application and gets invoked:

var workflowDefinition = activityResolver.Resolve(new WorkflowIdentity(operation.WorkflowVersion, operation.WorkflowName, operation.WorkflowXaml));

var application = new WorkflowApplication(workflowDefinition.Implementation);

response = activityInvoker.Resume<ResumeOperationResponse>(application, instanceStoreProvider.Create(), resumeContext, out outArguments);

Inside the invoker the resume method does this and fails:

    public TResponse Resume<TResponse>(WorkflowApplication application, InstanceStore instanceStore, ResumeBookmarkContext<ResumeOperationRequest> resumeContext,
        out IDictionary<String, object> outArguments)
        where TResponse : ResumeOperationResponse, new()
    {
        var response = new TResponse();
        outArguments = new Dictionary<string, object>();
        IDictionary<string, object> wfOutArguments = new Dictionary<string, object>();

        application.InstanceStore = instanceStore;

        try
        {
            application.Load(resumeContext.WorkflowInstanceId);
        } 
        catch (Exception exp)
        {
             //Exception happens here 
        }
    }

At this point I'm interested in pointers in what could be causing this.

There seems to be no way to debug it and get to the actual cause of the problem.

Many thanks

1
WF is a pain in the rear end so I feel for you. It is indeed a desert out there. Do you know if the workflow you're trying to resume was successfully persisted? Were there, by any chance, persistance errors before so that the instance never persisted so it cannot be resumed? Just a thought. - Tombala
Also, are you handling all the WorkflowApplication events when executing? It might help you "debug" if you add all the event handlers when you're executing to see if the workflow you are trying to resume was actually successful before. - Tombala
Well the instance store contains the instance data which contains the resume bookmarks and even though I'm not very experienced with the instance store it looks no different to the other bookmarks that actually work. As for the workflow itself, we have internal logic that stores the version of the xaml that was used when the operation for first created and I've debugged this and it looks correct. I'll add some of that code in my question - Nick
I don't know if it makes a difference but when we're loading an application for resuming, we not only pass the activity to it but also the workflow identity using the two parameter constructor of WorkflowApplication. - Tombala
By the way, we also have a SqlTrackingParticipant that we add to the workflow app to log everything. That sometimes can catch and log errors that might help in debugging. I think it's in one of the samples that come with the workflow SDK. msdn.microsoft.com/en-us/library/ee622983.aspx - Tombala

1 Answers

0
votes

The workflow application throws this error when you put the Load method in the try catch. In my application, if i put the Load method call in a try/catch, it would change the guid right before it calls the method and thus will throw this exception. My fix was to take out the try catch from this method and add it on the caller that was calling this method.