Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

So, my code has been working ok. I have a state-safe workflow, which means that if the workflow engine stops and unloads, then it should be able to start back where I left it.

There are some stages that perform some setup (such as subscribing to events for eg) which I need to make sure is done if the workflow is loaded in a later stage.

For example:
Tracker Workflow Starts:
   state1: setup (subscribe to events)
   state2: wait for event (requires subscription to event)
   state3: report back to parent workflow


if the workflow is stopped (shutdown / crash) at stage 2, then I need to resubscribe to the event.

I added a method to the baseclass of the stages that runs only if the workflow is reloaded from a shutdown state. I can override it in state2 and resubscribe.

If I do not shut down the workflow, the following code runs fine:
C#
public static IWorkflow LoadWorkflow(Workflow workflowInfo)
{
    Type type = LoadWorkflowType(workflowInfo);

    MethodInfo method = type.GetMethod("DeSerialize", Flags);
    if (method == null && type.BaseType != null)
        method = type.BaseType.GetMethod("DeSerialize", Flags | BindingFlags.InvokeMethod).MakeGenericMethod(type);

    if (method == null)
        throw new NullReferenceException("No DeSerialize method found!");

    IWorkflow workflow = (IWorkflow)method.Invoke(type, new object[] { workflowInfo });

    return workflow;
}


If I do restart it then I get an error at the invocation:
Quote:
Object of type 'WorkFlowEngine.Projections.Workflow' cannot be converted to type 'WorkFlowEngine.Projections.Workflow'.

I think that this is because one version of the assembly is loaded at runtime (Type type), whilst the other is a direct reference (the input parameter of "Deserialize").

i would like to convert the loaded version of type to the referenced version of 'WorkFlowEngine.Projections.Workflow'.

Is that even possible?
Is there a better way I can do this?


Thanks ^_^
Andy
Posted
Updated 16-Jun-15 3:25am
v2

1 solution

Solved - Man, this is a pain!

You need to make sure that the base types for EVERYTHING you invoke is reference from a different library to the loaded assemblies.

It only means re-shuffling half you code >_<<br mode="hold" />

So:
If your loading assembly is the base type assembly then it will already be loaded into the appdomain.
If your base class is in the loaded assembly then it will be loaded once by the appdomain as a reference and again as the loaded assembly. This means that the assemblies are not the same instance, and although they are identical, they will never match.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900