Conleth

I have a created a workflowhost project that hosts a workflow runtime and returns instances of workflows.

I reference this project from a windows form and start a really simple workflow. I am able to start and run the workflow. I can suspend, resume, abort and unload the workflow. When it unloads I can see that it is stored in my persistence database ... however when I try to get the workflow

(WorkflowInstance workflowInstance = workflowRuntime.GetWorkflow(workflowInstanceId);) I get the error

Error binding to target method (stack trace is below).

The really strange thing is that if I create a new workflowRuntime using the same config file (with standard persistence service) and try to get the workflow instance it works! Why do I have to create a second runtime to access the workflow instead of using the first runtime The first runtime is still loaded, and IsStarted, it just errors.

Has anyone seen this before

Stack Trace:

" at System.DelegateSerializationHolder.GetDelegate(DelegateEntry de, Int32 index)\r\n at System.DelegateSerializationHolder.GetRealObject(StreamingContext context)\r\n at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)\r\n at System.Runtime.Serialization.ObjectManager.DoFixups()\r\n at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)\r\n at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity, IFormatter formatter)\r\n at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity)\r\n at System.Workflow.Runtime.Hosting.WorkflowPersistenceService.RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity)\r\n at System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService.LoadWorkflowInstanceState(Guid id)\r\n at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)\r\n at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance)\r\n at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId)\r\n at WorkflowHostApp.Form1.btnControlWorkflowInstance_Click(Object sender, EventArgs e) in C:\\Windows Workflow Foundation\\PresentingWindowsWorkflowFoundation_WFBeta2_2006-03-06\\PresentingWindowsWorkflowFoundation_WFBeta2_2006-03-06\\Chapter11\\WorkflowHostApp\\Form1.cs:line 266\r\n at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)\r\n at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)\r\n at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)\r\n at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)\r\n at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)\r\n at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)\r\n at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)\r\n at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n at System.Windows.Forms.ToolStrip.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at WorkflowHostApp.Program.Main() in C:\\Windows Workflow Foundation\\PresentingWindowsWorkflowFoundation_WFBeta2_2006-03-06\\PresentingWindowsWorkflowFoundation_WFBeta2_2006-03-06\\Chapter11\\WorkflowHostApp\\Program.cs:line 43\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"


Re: Windows Workflow Foundation Error binding to target method in GetWorkflow

v-mimurp

I have a similar stack trace (see below) from a senario where I am dynamically loading WF types, schematically, as follows:

Assembly.Load(r.ReadBytes(<length of base stream>)).GetType(typeName)

This works much of the time, but when the type contains a While activity (from WF extensions) I get the exception as depicted below. When the assembly is dynamically loaded from the executable folder, as in:

Assembly.Load(assemblyName).GetType(typeName)

the exception does not occur. For what it is worth, the While activity is using a CodeCondition handler.

If anybody has insight, I would appreciate it very much!!

Mike

--

System.Runtime.Serialization.SerializationException: System.Runtime.Serialization.SerializationException: Error binding to target method. ---> System.ArgumentException: Error binding to target method.
at System.Delegate.InternalCreateDelegate(Type type, Object firstArgument, MethodInfo method)
at System.DelegateSerializationHolder.GetDelegate(DelegateEntry de, Int32 index)
--- End of inner exception stack trace ---
at System.DelegateSerializationHolder.GetDelegate(DelegateEntry de, Int32 index)
at System.DelegateSerializationHolder.GetRealObject(StreamingContext context)
at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)
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.Clone()
at System.Workflow.ComponentModel.ActivityExecutionContextManager.CreateExecutionContext(Activity activity)
at System.Workflow.Activities.WhileActivity.TryNextIteration(ActivityExecutionContext context)
at System.Workflow.Activities.WhileActivity.Execute(ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.CompositeActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutionFilter.Execute(Activity activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.FaultAndCancellationHandlingFilter.Execute(Activity activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)
at System.Workflow.Runtime.Scheduler.Run()






Re: Windows Workflow Foundation Error binding to target method in GetWorkflow

Conleth

I've fixed the problem.

I load an activity assembly from a location defined in the app.config to the runtime before I start it. I had an old version of the assembly in the folder that the form was deployed. When the workflow was loading, it looks in the deployment folder first and was picking up the old assembly, instead of using the assembly that was added to the runtime.

I temporarily fixed it by loading all assemblies from the location the form is deployed and pointing the app.config to that location. I will now look to add an extra path to the AppDomain for a better solution.





Re: Windows Workflow Foundation Error binding to target method in GetWorkflow

konanki

Hi ,

I am getting Same error when i used while loop in workflow plz tell answer .

i am sending my code also.

GetRuntimeAssembly objruntime = new GetRuntimeAssembly();

using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())

{

Assembly MyAssembly;

MyAssembly = objruntime.GetDynamicAssembly();

AutoResetEvent waitHandle = new AutoResetEvent(false);

workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)

{

// Console.WriteLine(e.OutputParameters["Grade"].ToString());// this is used to get the value from the WorkFlow

Console.Read();

waitHandle.Set();

};

workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)

{

Console.WriteLine(e.Exception.Message);

// Console.Read();

waitHandle.Set();

};

workflowRuntime.WorkflowSuspended += delegate(object sender, WorkflowSuspendedEventArgs e)

{

Console.WriteLine("Workflow Suspended");

e.WorkflowInstance.Resume();

Console.Read();

};

workflowRuntime.WorkflowResumed += delegate(object sender, WorkflowEventArgs e)

{

Console.WriteLine("Workflow Resumed");

Console.Read();

};

Type[] typeval;

typeval = MyAssembly.GetTypes();


WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeval[1]);


instance.Start();


Console.Read();

Console.Read();

//Console.ReadLine();

}

Console.Read();

Console.Read();

runtime aassembly class is

class GetRuntimeAssembly

{

public Assembly GetDynamicAssembly()

{

Assembly MyAssembly, objExecutingAssemblies;

string strTempAssmbPath = "";

objExecutingAssemblies = Assembly.GetExecutingAssembly();

AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();

strTempAssmbPath = @"\..\WorkflowDesignerExample\bin\Debug\onStatus.dll";

.//Load the assembly from the specified path.

MyAssembly = Assembly.LoadFrom(strTempAssmbPath);

//Return the loaded assembly.

return MyAssembly;

}//end of function