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