locked
CreateInstance failed for type CustomActivity. Exception has been thrown by the target of an invocation. RRS feed

  • Question

  • Hi all,

    I have created a workflow executable, generated using CodeDom, which allows to take in a xoml file and and execute it. I have custom activities in the xoml file. Whenever I try to execute the workflow executable, it will always throw me an error :
    error 347: CreateInstance failed for type CustomActivity1. Exception has been thrown by the target of an invocation at the red portion of the code.  Any solutions or suggestions? Code eg. as below:

    Code Snippet

    public class WorkflowExecute
        {
            private static WorkflowRuntime workflowRuntime;
            private static WorkflowInstance instance;
            private static XmlReader reader;
            private static string xomlFile = "test.xoml";
            static void Main()
            {
                try
                {
                    workflowRuntime = new WorkflowRuntime();
                    TypeProvider typeProvider = new TypeProvider(null);

     typeProvider.AddAssemblyReference("WorkflowLib.dll");

     typeProvider.AddAssemblyReference("WorkflowDataLib.dll");

     typeProvider.AddAssemblyReference("CustomActivity1.dll"); 

                    workflowRuntime.AddService(typeProvider);
                    reader = XmlReader.Create(xomlFile);

          instance = workflowRuntime.CreateWorkflow(reader);

                    instance.Start();
                }
                catch (WorkflowValidationFailedException e)
                {
                    TextWriter tw = new StreamWriter("error.txt");
                    tw.WriteLine(e.ToString());
                    foreach (ValidationError er in e.Errors)
                    {
                        tw.WriteLine(er.ToString());
                    }
                    tw.Close();
                    
                }
                finally { reader.Close(); }
            }
        }




    Wednesday, May 14, 2008 7:03 AM

Answers

  • Hi,

    I have resolved the issue. Its due to a missing dll file that is reference by the parent activity inherited by the custom activity. Thanks
    Thursday, May 22, 2008 1:41 AM

All replies

  • Can you please post the xoml file you are using?

     

    Thanks

     

    Yuan Hu

    Wednesday, May 14, 2008 9:02 AM
    Moderator
  • <ns0Tongue TiedequentialEventHandlingWorkflow x:Name="SequentialEventHandlingWorkflow" SetNumber="301" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:ns1="clr-namespace:CustomActivity;Assembly=CustomActivity1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:WorkflowLib;Assembly=WorkflowLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <ns0:NPSEventHandlersActivity x:Name="npsEventHandlersActivity1">
            <ns0:NPSEventDrivenActivity x:Name="npsEventDrivenActivity1">
                <ns0:HandleExternalDataActivity x:Name="HandleActivity" EventName="StopModuleEvent" InterfaceType="{x:Type ns0:ILocalService}" />
            </ns0:NPSEventDrivenActivity>
        </ns0:NPSEventHandlersActivity>
        <ns0Tongue TiedequentialWorkflow x:Name="sequentialWorkflow1">
            <ns1:CustomActivity1 x:Name="customActivity1" RemoteNode="{x:Null}" RawFilePath="CustomActivity1.dll" TimeoutValue="0" InputParamFile="" />
        </ns0Tongue TiedequentialWorkflow>
        <FaultHandlersActivity x:Name="faultHandlersActivity1">
            <FaultHandlerActivity x:Name="faultHandlerActivity1" FaultType="{x:Type WorkflowTerminatedException}" />
        </FaultHandlersActivity>
    </ns0Tongue TiedequentialEventHandlingWorkflow>
    Wednesday, May 14, 2008 9:10 AM
  • Can you execute CustomActivity1 separately? I guess there is something wrong with it.

     

    Thanks

     

    Yuan Hu

    Wednesday, May 21, 2008 11:54 AM
    Moderator
  • Hi,

    I have resolved the issue. Its due to a missing dll file that is reference by the parent activity inherited by the custom activity. Thanks
    Thursday, May 22, 2008 1:41 AM
  • I've been having the same error crop up. I don't know the solution, but the following workaround (suggested by Omar for fixing a different issue) seems to resolve it, at least temporarily:

    - Close all windows in solution.
    - Clean solution
    - Close VS
    - Re-open VS
    - Build solution.

    Can anyone at MS confirm whether this is a bug?

    Cheers,
    Peter.
    Tuesday, July 22, 2008 6:45 AM
  • Hi Logan Kong.

     

    I have similar problem. I use AddAssemblyreference to get .dll file generated by myLibrary project.

     

    myLibrary contains custom activity and root acitvity(parent activity)"BaseWorkflow".

     

    I got same error:  Re: CreateInstance failed for type BaseWorkflow. Exception has been thrown by the target of an invocation.

     

    give me response, if you read it.

    thanks

     

     

     

    Friday, November 7, 2008 3:46 AM