Compile error - type resolution

Hello,
I have a basic workflow (xoml-only based) as following:

<SequentialWorkflowActivity x:Class="XomlWithRules.Workflow1" x:Name="Workflow1" xmlns:ns0="clr-namespace:XomlWithRules" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
 <ns0:TestActivity x:Name="myActivity" IsTrue="False" />
</SequentialWorkflowActivity>

TestActivity is defined in the same console application (where it workflow is hosted). Whe I execute the following code:

WorkflowCompilerResults CompileWorkflow()
{
    String[] assemblyNames = { "XomlWithRules.exe" };
    WorkflowCompilerParameters parameters = new WorkflowCompilerParameters(assemblyNames);
    parameters.OutputAssembly = "CustomWorkflow.dll";
    parameters.LibraryPaths.Add(Path.GetDirectoryName(typeof(TestActivity).Assembly.Location));

    WorkflowCompiler compiler = new WorkflowCompiler();
    WorkflowCompilerResults compilerResults = compiler.Compile(parameters, wfFile);

    foreach (CompilerError compilerError in compilerResults.Errors)
    {
        Console.WriteLine(compilerError.ToString());
    }

    return compilerResults;
}

I get the following error message:

error 347: Could not deserialize object. The type 'XomlWithRules.TestActivity' could not be resolved.} System.CodeDom.Compiler.CompilerError

The TestActivity is declared as:

public class TestActivity : System.Workflow.ComponentModel.Activity
{
 public TestActivity()
 {
        this.Name = "myActivity";
 }

    private bool isTrue;

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public bool IsTrue
    {
        get { return isTrue; }
        set { isTrue = value; }
    } 

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        isTrue = true;
        Console.WriteLine("Activity done : " + IsTrue.ToString());
        return ActivityExecutionStatus.Closed;
    }
}

Any idea

Thanks,
Pierre




Answer this question

Compile error - type resolution

  • Mini

    Hello Angel,
    I added the assembly info but when I compile the solution I get the following compilation error:

    "A namespace does not directly contain members such as fields or methods D:\Code\WWF\XomlWithRules\Workflow1.xoml"

    Consider that I upgraded to beta 2.2.

    Thanks,
    Pierre



  • fparc

    Hi Angel,
    that didn't solved the problem.

    Thanks,
    Pierre



  • Vita

    Hi Pierre,

    I tried your example and ran into the same problem. The issue here is the following line:

    xmlns:ns0="clr-namespace:XomlWithRules"

    This namespace needs to have the assembly name tagged to it or there is no way that the compiler can resolve it. Here's what it should look like with the assembly info:

    xmlns:ns0="clr-namespace:XomlWithRules;Assembly=XomlWithRules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

    Thanks!
    Angel



  • paulains

    Ok, I made further researches. When I execute with the suggested update I get the following error message:

    "- [0] {error 347: Could not deserialize object. The type 'clr-namespace:XomlWithRules;XomlWithRules, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null.TestActivity' could not be resolved.} System.Workflow.ComponentModel.Compiler.ValidationError"

    Consider that I have version 3.0.0.0 and not 1.0.0.0 (changing them the problem persists).

    Thanks,
    Pierre



  • Eric Harmon

    Hi Pierre,

    Instead of adding your assembly location to the LibrayPaths, add it to your ReferencedAssemblies:

    parameters.ReferencedAssemblies.Add(typeof(TestActivity).Assembly.Location);

    Let me know if this resolves your issue.

    Thanks!
    Angel



  • clovernet

    can you sync up AppDomain.CurrentDomain.AssemblyResolve event and return your assembly when requested

    this event gets fired when a type couldnt be resolved by other means



  • Ravi Teja

    Pierre,

    It looks like you just forgot to put "Assembly=" in your namespace definition: and it thinks that the assembly name and semi-colon are part of the namespace name:

    xmlns:ns0="clr-namespace:XomlWithRules;Assembly=XomlWithRules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"



  • blounsbury

    Hello Angel,
    you are right. Now the next problem is on the rules files:

    <RuleDefinitions xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
    <RuleDefinitions.Conditions>
    <RuleExpressionCondition Name="TestIsTrue">
    <RuleExpressionCondition.Expression>
    <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <ns0:CodeBinaryOperatorExpression.Left>
    <ns0:CodePropertyReferenceExpression PropertyName="IsTrue">
    <ns0:CodePropertyReferenceExpression.TargetObject>
    <ns0:CodeCastExpression>
    <ns0:CodeCastExpression.Expression>
    <ns0:CodeMethodInvokeExpression>
    <ns0:CodeMethodInvokeExpression.Parameters>
    <ns0:CodePrimitiveExpression>
    <ns0:CodePrimitiveExpression.Value>
    <ns1:String xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">myActivity1</ns1:String>
    </ns0:CodePrimitiveExpression.Value>
    </ns0:CodePrimitiveExpression>
    </ns0:CodeMethodInvokeExpression.Parameters>
    <ns0:CodeMethodInvokeExpression.Method>
    <ns0:CodeMethodReferenceExpression MethodName="GetActivityByName">
    <ns0:CodeMethodReferenceExpression.TargetObject>
    <ns0:CodeThisReferenceExpression />
    </ns0:CodeMethodReferenceExpression.TargetObject>
    </ns0:CodeMethodReferenceExpression>
    </ns0:CodeMethodInvokeExpression.Method>
    </ns0:CodeMethodInvokeExpression>
    </ns0:CodeCastExpression.Expression>
    <ns0:CodeCastExpression.TargetType>
    <ns0:CodeTypeReference ArrayElementType="{p11:Null}" BaseType="XomlWithRules.TestActivity" Options="0" ArrayRank="0" xmlns:p11="http://schemas.microsoft.com/winfx/2006/xaml" />
    </ns0:CodeCastExpression.TargetType>
    </ns0:CodeCastExpression>
    </ns0:CodePropertyReferenceExpression.TargetObject>
    </ns0:CodePropertyReferenceExpression>
    </ns0:CodeBinaryOperatorExpression.Left>
    <ns0:CodeBinaryOperatorExpression.Right>
    <ns0:CodePrimitiveExpression>
    <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>
    </ns0:CodeBinaryOperatorExpression.Right>
    </ns0:CodeBinaryOperatorExpression>
    </RuleExpressionCondition.Expression>
    </RuleExpressionCondition>
    </RuleDefinitions.Conditions>
    </RuleDefinitions>

    I get the error "error 1368: Activity 'ifElseBranchActivity1' validation failed: Property "Condition" has invalid value. Condition expression is invalid. The type name specified ("XomlWithRules.TestActivity") can not be resolved.} System.Workflow.ComponentModel.Compiler.ValidationError"

    How can I indicate the assembly reference for the base type

    Thanks,
    Pierre



  • Compile error - type resolution