0
votes

I'm having problems when I try to load a workflow from the instance store. Its seems that it can't deserialize this workflow.

This is my code:

//Get workflow through WorkflowDefinitionManager
        Activity workflow = WorkflowDefinitionManager.GetWorkflow(wfDefinitionId);

        //Create wf application
        WorkflowApplication instance = new WorkflowApplication(workflow);
        instance.InstanceStore = InstanceStore;

        instance.Completed += WorkflowApplication_OnCompleted;
        instance.Aborted += WorkflowApplication_OnAborted;
        instance.Idle += WorkflowApplication_OnIdle;
        instance.OnUnhandledException += WorkflowApplication_OnUnhandledException;
        instance.PersistableIdle += WorkflowApplication_OnPersistableIdle;

        instance.Load(inGuid);  //<--- I get the error here

Error:

The deserializer cannot load the type to deserialize because type 'System.Activities.Variable`1+VariableLocation[[MYCLASS, MYASSEMBLY, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.

I don't understand why I get this error if I can start and persist the workflow before. Could you help me? Please

Thanks

2

2 Answers

0
votes

There could be a couple of reasons.

The most common is that the workflow definition changed between the time it was persisted and the time you are reloading it. This is a no go at the moment.

Another possibility is that the workflow was started on one machine and later resumed on another machine that doesn't have all required assemblies to resume it.

The other possibility is that the type in question was already loaded because of some other code executing the first time and is not loaded when you reload the workflow state. Now normally the assembly would just be found and loaded using the CLR rules but it might not be available using normal rules.

0
votes

Finally I solved my errors resolving the assemblies in runtime:

AppDomain appDomain = AppDomain.CurrentDomain;
appDomain.AssemblyResolve += AppDomain_AssemblyResolve;
instance.Load(inGuid);
appDomain.AssemblyResolve -= AppDomain_AssemblyResolve;

This is the callback:

private Assembly AppDomain_AssemblyResolve(object sender, ResolveEventArgs e)
    {

        try
        {
            string strTempAssmbPath = ExtensionsFolder + e.Name.Substring(0, e.Name.IndexOf(",")) + ".dll";
            return Assembly.LoadFile(strTempAssmbPath);
        }
        catch (Exception ex)
        {
            log.Error(ex);

        }
        return null;
    }