Error: Changing a workflow and getting a state on a persisted Workflow Instance

October 6, 2006

I was experimenting with Persistance and created some workflow instances and unloaded them. these appeared in my database with appropriate Guid's. I then closed the application and reopened it and returned the State of the workflow fine using:

    StateMachineWorkflowInstance stateMachineWorkflowInstance = new StateMachineWorkflowInstance(workflowRuntime, instanceId);
    state = stateMachineWorkflowInstance.CurrentState.Name;


I closed the application again and then modified the workflow in the designer adding a new state and putting it between the two existing states using SetState activities.
When I compiled and ran the application again and tried to return the State I got the following error:

Index was outside the bounds of the array.
System.Runtime.Serialization.SerializationException was unhandled
  Message="The object with ID 28 implements the IObjectReference interface for which all dependencies cannot be resolved. The likely cause is two instances of IObjectReference that have a mutual dependency on each other."
  Source="mscorlib"
  StackTrace:
       at System.Runtime.Serialization.ObjectManager.GetCompletionInfo(FixupHolder fixup, ObjectHolder& holder, Object& member, Boolean bThrowIfMissing)
       at System.Runtime.Serialization.ObjectManager.CompleteObject(ObjectHolder holder, Boolean bObjectFullyComplete)
       at System.Runtime.Serialization.ObjectManager.DoFixups()
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
       at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity, IFormatter formatter)
       at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity)
       at System.Workflow.Runtime.Hosting.WorkflowPersistenceService.RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity)
       at System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService.LoadWorkflowInstanceState(Guid id)
       at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)
       at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance)
       at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId)
       at System.Workflow.Activities.StateMachineWorkflowInstance..ctor(WorkflowRuntime runtime, Guid instanceId)
       at TestApp.WorkFlowEngine.GetState(WorkflowRuntime workflowRuntime, Guid instanceId, String& state) in C:\temp\Technologies\Tracking\SimpleTrackingSample\CS\TestApp\WorkFlowEngine.cs:line 42
       at TestApp.Form1.GetState() in C:\temp\Technologies\Tracking\SimpleTrackingSample\CS\TestApp\Form1.cs:line 122
       at TestApp.Form1.btnLoadWorkflow_Click(Object sender, EventArgs e) in C:\temp\Technologies\Tracking\SimpleTrackingSample\CS\TestApp\Form1.cs:line 81
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at TestApp.Program.Main() in C:\temp\Technologies\Tracking\SimpleTrackingSample\CS\TestApp\Program.cs:line 18
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


Inspecting the database and looking at the Workflow table showed that there was only one row in there with the WorkflowDefinition column being:

<ns0:Workflow1 InitialStateName="Workflow1InitialState" x:Name="Workflow1" DynamicUpdateCondition="{x:Null}" CompletedStateName="{x:Null}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:Microsoft.Samples.Workflow.SimpleTrackingSample;Assembly=SimpleTrackingSample, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null" />


Obviously it isn't seeing the change made as a different version and existing instances must just reference this Workflow.

What is the procedure for changing a workflow and allowing existing instances to still be loaded from persisted state?

Also, is there a way that the existing instances could take on the changes to the workflow. Obviously this gets extremely compilcated in the fact that if you remove a state from a diagram and the instance is in that state decisions will have to be made on what state it should be in.

I've posted this on the MSDN forums and hopefully someone will point me in the right direction. 

UPDATE 

"If you change the definition of a workflow and recompile it you need to change the assembly version.  The existing instances (unloaded or in memory) need the original version of the type/assembly in order to be deserialized correctly.  If you need to change the definition of an "in-flight" running instance you'll need to use the dynamic update functionality.

Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting"

 Guess I'll need to look into dynamically updating the workflow on the fly and seeing how it handles this.

A few forum posts here: 1 2  

 

diigo itdeliciousdiggfacebookreddit

Comments

Tuesday, 17 Jun 2008 03:22 by Lyn England
planful noninjurious arbitrament reimpatriate erosion outdraft peakedness hygroscopy Dave Dreblow - Better Homes Realty http://www.hellynewport.com

Monday, 28 Jul 2008 08:58 by nick
3DBZda hi! hice site!

Thursday, 31 Jul 2008 06:18 by sylvia
bookmark you thx adipex pills ledjzc

Friday, 1 Aug 2008 06:51 by kris
i say one thing phentermine online 01584

Friday, 1 Aug 2008 09:20 by mona
hay buy vicodin odvxp tramadol cod 130850

Saturday, 2 Aug 2008 12:11 by adult
i say one thing vicodin no prescription 973

Saturday, 2 Aug 2008 05:33 by james
hi nice site thx hydrocodone pills 68608

Saturday, 16 Aug 2008 07:34 by kris
interesting site man

Wednesday, 20 Aug 2008 02:04 by adult
hello everybody! canada in louis replica sold vuitton 879 cerises louis vuitton replica 1509

Saturday, 6 Sep 2008 01:29 by sylvia
good work man ativan addiction 8-P buy xanax online 0111 music ringtone 403117 buy vicodin xuv cheap clonazepam 734

Saturday, 6 Sep 2008 04:27 by bob
good site dude

Saturday, 6 Sep 2008 08:54 by xFVQAWJRSXqpBdDD
oJCjDV spam_15.txt;5;10

Monday, 22 Sep 2008 03:55 by bob
nice site dude vmxkon clonazepam pills uftel

Tuesday, 23 Sep 2008 04:28 by lola
please look at this buy ephedrine :-)

Tuesday, 23 Sep 2008 04:28 by lola
please look at this buy ephedrine :-)

Tuesday, 23 Sep 2008 04:58 by arni
cool site man levitra no prescription vjmfvc order adipex >:))

Monday, 29 Sep 2008 03:26 by james
it's nice site cheapest phentermine cxbb cheap soma %-OOO

Wednesday, 1 Oct 2008 05:12 by james
please look at this valium pills :-]]]

Thursday, 2 Oct 2008 05:05 by lola
bookmark you thx online tramadol 529094 vicodin online >:OO order viagra :OOO

Tuesday, 7 Oct 2008 10:25 by bred
hello everybody! purchase levitra >:O

Wednesday, 8 Oct 2008 12:11 by john
please look at this cheapest hydrocodone ausfd adipex diet pills tpi

Friday, 10 Oct 2008 05:43 by lola
cool site man order cialis 3379

Friday, 10 Oct 2008 08:01 by bob
i say one thing levitra addiction =)

Saturday, 11 Oct 2008 12:55 by james
it's nice site buy ephedrine %-OOO diazepam no prescription qtkfq

Monday, 13 Oct 2008 05:58 by joseph
please look at this buy phentermine axqds cialis sample free hexsol ultram online htde order ephedrine 436506 order lipitor =OO cheap levitra aindrm

Saturday, 18 Oct 2008 10:56 by kate
interesting post thx purchase viagra sezp cheap cialis 8-((( cheap phentermine 791710 tramadol =-OO order adipex 587 cheap thyroid =DD lorazepam addiction 60023 cheap prozac %O propecia addiction >:(((

Sunday, 19 Oct 2008 08:18 by mona
nice site dude clonazepam no prescription igmcbg generic tramadol 011559 ephedrine diet pills 08154

Wednesday, 22 Oct 2008 10:56 by lola
fSI0ys see this thanks nexium addiction 61171 buy fioricet online :OOO cheap celebrex 70438 codeine no prescription svh

Saturday, 1 Nov 2008 02:35 by arni
cool site man bollywood ringtones 892549 office ringtone pkuao ringtones to download 14661

Tuesday, 4 Nov 2008 09:31 by kate
it's nice site!!! cheapest zoloft 429706 carisoprodol =]] nexium no prescription 4413 ultram cikb

Wednesday, 5 Nov 2008 08:40 by bred
good work man order ambien 8PPP purchase ativan 0801 fioricet online pohp generic diazepam :-]]

Wednesday, 5 Nov 2008 11:30 by lola
sweet site thx cheapest levitra uxoqrb buy lipitor 8223 cheap ephedrine 37209 order clonazepam :-DD

Thursday, 6 Nov 2008 10:30 by ben
it's nice site!!! lipitor pills xpuyv buy phentermine 2913 generic clonazepam 8-(

Monday, 10 Nov 2008 04:14 by adult
great work man thx what are the side effects of adipex 89789 herbal adipex 650574 order adipex deliver cod 40381 adipex online from overseas 66239

Monday, 10 Nov 2008 04:15 by adult
great work man thx what are the side effects of adipex 89789 herbal adipex 650574 order adipex deliver cod 40381 adipex online from overseas 66239

Monday, 10 Nov 2008 07:03 by liza
sweet site thx adipex_drug_test eqafgq money order prescription adipex %] buy cheap adipex :OOO tramadol cod saturday delivery 287323

Tuesday, 11 Nov 2008 12:20 by bred
it's nice site oxycodone with tramadol =-OOO tramadol no prescription 32492 tramadol generic ultram 8PPP adipex clinics 8[[[

Tuesday, 11 Nov 2008 09:47 by james
it's nice site tramadol 62870 adipex p kfmg tramadol overnight 215 adipex order online without prescription :)))

Tuesday, 11 Nov 2008 09:47 by james
it's nice site tramadol 62870 adipex p kfmg tramadol overnight 215 adipex order online without prescription :)))

Tuesday, 11 Nov 2008 01:41 by bob
see this thanks adipex alternatives ucq tramadol dosage qsifmt cheap tramadol without prescription zbcwh fibromyalgia tramadol mbr

Tuesday, 11 Nov 2008 07:15 by liza
sweet site thx adipex and 50 us states pitnwh adipex fedex overnight woxqym ordering adipex %]]] adipex diet pills compare best prices :OO

Tuesday, 11 Nov 2008 10:08 by liza
good post man thx adipex diet pill prescription strongest 20 =-DD adipex buy inurl %[[ ultram tramadol hcl 79274 what is tramadol 8]]]

Wednesday, 12 Nov 2008 06:59 by liza
i say one thing tramadol hydrochloride 66106 adipex no prescription to dc fox cheapest adipex >:D humana health care adipex diet pill avm

Wednesday, 12 Nov 2008 10:12 by arni
it's nice site order tramadol %-[[[ tramadoll :OOO ordering adipex online =-(( adipex hurt me 771979

Wednesday, 12 Nov 2008 11:01 by james
good post man thx cheapest online adipex 8) tramadol water soluble 735075 buy adipex online without prescription 8778 adipex effects on adhd rtcrvl

blog comments powered by Disqus