MikeMu

Sorry for the repost, but I'm having problems getting the While activity to work when running from a dynamically loaded assembly. By dynamic, I mean as in "Assembly.Load(r.ReadBytes())..." I cannot tell whether this is a bug in WF, or an incorrect expectation on my part.

Below, I have attached a simple reproduce case. It attempts to run a simple workflow containing a While activity out of the WorkflowLibrary1.dll assembly (this is not included here, but should be easily constructed.)

Any opinions Thanks!

using System;
using System.IO;
using System.Reflection;
using System.Workflow.Runtime;

namespace DynamicWFLoadProblem
{
class Program
{


// this doesn't work... System.Runtime.SerializationException: Error binding to target method.
static Assembly GetAssembly1()
{
string assemblyPath = Path.Combine(Directory.GetCurrentDirectory(), @"WorkflowLibrary1.dll");
Assembly assembly;
using (BinaryReader r = new BinaryReader(File.OpenRead(assemblyPath)))
{
assembly = Assembly.Load(r.ReadBytes((int)r.BaseStream.Length));
}
return assembly;
}

// this works...
static Assembly GetAssembly2()
{
return Assembly.Load(@"WorkflowLibrary1");
}

static void Main()
{
Assembly assembly = GetAssembly1(); // change to GetAssembly2() to see it work

using (WorkflowRuntime runtime = new WorkflowRuntime())
{
runtime.WorkflowStarted += delegate { Console.WriteLine("WF started"); };
runtime.WorkflowCompleted += delegate { Console.WriteLine("WF completed"); };
runtime.WorkflowTerminated += delegate(object s, WorkflowTerminatedEventArgs e) { Console.WriteLine("WF terminated: " + e.Exception); };
runtime.StartRuntime();

Type workflowType = assembly.GetType("WorkflowLibrary1.Workflow1");

WorkflowInstance instance = runtime.CreateWorkflow(workflowType);
instance.Start();

Console.ReadLine();
}
}
}
}




Re: Windows Workflow Foundation REPOST: Assembly.Load(r.ReadBytes()).GetType(typeName): TargetInvocationException thrown when type contains While activity

Ram Venkatesan - MSFT

Hi Mike

We are looking into this. We will get back to you once we identify the issue.

Thanks

-ram





Re: Windows Workflow Foundation REPOST: Assembly.Load(r.ReadBytes()).GetType(typeName): TargetInvocationException thrown when type contains While activity

MikeMu

Thanks! I look forward to hearing back.