RunWorkflow from *.xoml ,*.rules?

Question:

 1 ) This Workflow have base workflow and CustomActivity

  in Project Workflow.Base
    public partial class BaseWorkflow : SequentialWorkflowActivity
    {
 
        private bool _Result;
        public bool Result
        {
            get { return _Result; }
            set { _Result = value; }
        }
 
        private string _WorkflowName;
        public string WorkflowName
        {
            get { return _WorkflowName; }
            set { _WorkflowName = value; }
        }
    }
 
    public partial class MessageBoxActivity :Activity
    {
        private string message;
 
        public string Message
        {
            get { return message; }
            set { message = value; }
        }
 
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            MessageBox.Show(this.message);
 
            return ActivityExecutionStatus.Closed;
        }
    }
2) I Create TestBaseWorkflow.xoml and TestBaseWorkflow.rules
TestBaseWorkflow.xoml:
<ns0:BaseWorkflow  x:Name="TestBaseWorkflow" Result="False" WorkflowName="{x:Null}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:Workflow.Base;Assembly=Workflow.Base, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null">
  <IfElseActivity x:Name="ifElseActivity1">
    <IfElseBranchActivity x:Name="ifElseBranchActivity1">
      <IfElseBranchActivity.Condition>
        <RuleConditionReference ConditionName="Condition1" />
      </IfElseBranchActivity.Condition>
      <ns0:MessageBoxActivity Message="true" x:Name="messageBoxActivity1" />
    </IfElseBranchActivity>
    <IfElseBranchActivity x:Name="ifElseBranchActivity2">
      <ns0:MessageBoxActivity Message="fasle" x:Name="messageBoxActivity2" />
    </IfElseBranchActivity>
  </IfElseActivity>
</ns0:BaseWorkflow>
 
TestBaseWorkflow.rules:
<RuleDefinitions xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
  <RuleDefinitions.Conditions>
    <RuleExpressionCondition Name="Condition1">
      <RuleExpressionCondition.Expression>
        <ns0:CodePrimitiveExpression xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <ns0:CodePrimitiveExpression.Value>
            <ns1:Boolean xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">true</ns1:Boolean>
          </ns0:CodePrimitiveExpression.Value>
        </ns0:CodePrimitiveExpression>
      </RuleExpressionCondition.Expression>
    </RuleExpressionCondition>
  </RuleDefinitions.Conditions>
</RuleDefinitions>
3) Run TestBaseWorkflow
//add Project Workflow.Base's DLL(Include class BaseWorkflow and MessageBoxActivity ) 
TypeProvider typeProviderWorkflow = new TypeProvider(workflowRuntime);
typeProviderWorkflow.AddAssembly(typeof(Workflow.Base.BaseWorkflow).Assembly);
workflowRuntime.AddService(typeProviderWorkflow);
 
 
string xomlFile = @"C:\Documents and Settings\Administrator\Desktop\code\BaseWorkflowFoundionSolution\Workflow.TestBase\TestBaseWorkflow.xoml";
string rulesFile = @"C:\Documents and Settings\Administrator\Desktop\code\BaseWorkflowFoundionSolution\Workflow.TestBase\TestBaseWorkflow.rules";
XmlTextReader readerWf = new XmlTextReader(xomlFile);
XmlTextReader readerRules = new XmlTextReader(rulesFile);
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(readerWf, readerRules, new Dictionary<string, object>());
workflowInstance.Start();
waitHandle.WaitOne();
 
4) catch Exception Message:

An unhandled exception of type 'System.NullReferenceException' occurred in System.Workflow.Runtime.dll

Additional information: Object reference not set to an instance of an object.

5) what can i do run TestBaseworkflow

 


 




Answer this question

RunWorkflow from *.xoml ,*.rules?

  • Doeb

    You can't run a workflow using the WorkflowMarkupSerializer. If you want to pass in a type you need to compile the workflow into an assembly first.

  • Abort Syntax

    It ran without any exceptions and the message box popped up with “true” as the text. Can you change your code to the following and post the output:

    try

    {

    WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(readerWf, readerRules, new Dictionary<string, object>());

    workflowInstance.Start();

    }

    catch (Exception exp)

    {

    Console.WriteLine(exp.StackTrace);

    }

    Without the stack trace it is impossible to determine the cause of your NullReferenceException.



  • Hugo from Holland

    What build are you using   Can you post the stack trace for the null reference exception   I followed your steps on Beta 2 build and did get any exceptions.

  • Sajal57918

    Thx tom.I have another quesion.

    if I will run workflow in WorkflowMarkupSerializer,where can i use TestBaseWorkflow.rules file

    code:

           string xomlFile = @"D:\aps.net\Base workflow\BaseWorkflowFoundionSolution\Workflow.TestBase\TestBaseWorkflow.xoml";
     
                XmlTextReader readerWf = new XmlTextReader(xomlFile);
                WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                SequentialWorkflowActivity wf1 = serializer.Deserialize(readerWf) as SequentialWorkflowActivity;
                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(wf1.GetType());
                workflowInstance.Start();


  • Randy Trihydro

    Sorry Tom , I didn't found the error before .
    I didn't bulid this project ,and only use file path to run workflow.
    This Project only include two files (TestBaseWorkflow.xoml and TestBaseWorkflow.rules)
    TestBaseWorkflow.xoml
    <ns0:BaseWorkflow  x:Name="TestBaseWorkflow" Result="False" WorkflowName="{x:Null}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:Workflow.Base;Assembly=Workflow.Base, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null">
      <IfElseActivity x:Name="ifElseActivity1">
        <IfElseBranchActivity x:Name="ifElseBranchActivity1">
          <IfElseBranchActivity.Condition>
            <RuleConditionReference ConditionName="Condition1" />
          </IfElseBranchActivity.Condition>
          <ns0:MessageBoxActivity Message="true" x:Name="messageBoxActivity1" />
        </IfElseBranchActivity>
        <IfElseBranchActivity x:Name="ifElseBranchActivity2">
          <ns0:MessageBoxActivity Message="fasle" x:Name="messageBoxActivity2" />
        </IfElseBranchActivity>
      </IfElseActivity>
    </ns0:BaseWorkflow>
    bulid error is :
    Cannot compile a markup file which does not contain declaration of the new workflow type.
    why have this error 
    can u send this test project to me  (caixikai@hotmail.com)
     
     
     


  • G Unot!

    The code build on Beta 2 and didnt get any exceptions.

    but if u run the code ,u can catch this exceptions .




  • Futura57

    You dont need to build a xaml only workflow. That is the whole point of having a xaml only workflow. Can you exactly try what Tom has suggested the previous post and let us know what error are you seeing.



  • nonoandy

    I try tom' suggestion.

    Runing project is ok.

    I only remove Workflow.Base.Test Project's refernce from project workflow.base.Test.Console .

    Workflow.Base.Test Project only have TestBaseWorkflow.xoml and TestBaseWorkflow.Rules.

    Thx tom and Vihang 's help.

    But i cannt bulid TestBaseWorkflow.xoml and TestBaseWorkflow.Rules to DLL file.

    I will use it in my engine.

    Buliding two files have the previous error.

    what can i do



  • Puneet Minda

    When you compile a Xoml file into a Type you need to have the class attribute, e.g. x:Class="NamespaceName.ClassName". If you are using Xoml activation, CreateWorkflow passing XmlReader, you can't have the class attribute.

  • RunWorkflow from *.xoml ,*.rules?