locked
Strange Workflow Problem RRS feed

  • Question

  • I am quite new in Workflows and working WF4 for now. I have strange problem;

    I have "WPF Control Library Project". In this project, a added an activity named Activity1. Then a WPF page. in page load, I tried to create an instance of the activity. Result is fine, everything ok. But when I add a extra namespace to the page (in WPF), the line that I created the activity instance, gives me an error, that it cannot find the definition of Activity1.

    I tried same thing in "Activity Library" same thing happens.

    When I separate Page and Activity to different DLLs this doesn't happen...

    Am I missing something ?

    Please help me...

    (I am using VS2010, FW4)


    dogu
    Wednesday, August 4, 2010 5:55 AM

Answers

  • Hi Dogu,
    I see, you're right, there's some more problems here.

    So here is beta 0.2 version of the workaround - define the default constructor to call InitializeComponent() using reflection:

    public Workflow1() : base()
    {
        Type thisType = this.GetType();
        MethodInfo initializer = thisType.GetMethod("InitializeComponent", BindingFlags.Public | BindingFlags.Instance);
        initializer.Invoke(
    this, new object[] { });
    }

    (InitializeComponent() is found in the generated file Workflow1.g.cs, but only after XamlBuildTask has run). 

    Tim

    • Marked as answer by Andrew_Zhu Wednesday, August 11, 2010 6:50 AM
    Tuesday, August 10, 2010 5:36 PM

All replies

  • Hi Dogu,

    Is the namespace you added to your WPF

    xmlns:local="clr-namespace:{SomeNamespaceInLocalAssembly}" ?

    There is a known compatibility problem between WPF Xaml and WF Xaml build tasks, which are separate. One way to work around the problem is by creating your WPF and WF classes in separate projects.

    I have also just thought of and tried out another workaround, which is to add an empty partial class definition to your project, like this (I like to put it in a file called Workflow1.xaml.cs):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Activities;

    namespace WorkflowConsoleApplication1 //should be  same namespace as in your activity XAML
    {
        partial class Workflow1 : Activity //Workflow1 = name of activity class in your activity XAML
        {
        }
    }

    With this, build worked for me.
    Tim

    Monday, August 9, 2010 4:07 AM
  • Tim,

    It works fine if workflow is parameterless. If workflow has parameters, partial class solution fails unfortunately. Do you know, any short term plan to patch this ?


    dogu
    Tuesday, August 10, 2010 12:50 PM
  • The problem is the class generated with xaml is not defined in compile time. So the partial class is not merged with any class, it compiled by itself (so that is why it must be derived from Activity and no property is visible). So, it is a blank activity and it doesn't hit any breakpoint in the original workflow...
    dogu
    Tuesday, August 10, 2010 1:40 PM
  • Hi Dogu,
    I see, you're right, there's some more problems here.

    So here is beta 0.2 version of the workaround - define the default constructor to call InitializeComponent() using reflection:

    public Workflow1() : base()
    {
        Type thisType = this.GetType();
        MethodInfo initializer = thisType.GetMethod("InitializeComponent", BindingFlags.Public | BindingFlags.Instance);
        initializer.Invoke(
    this, new object[] { });
    }

    (InitializeComponent() is found in the generated file Workflow1.g.cs, but only after XamlBuildTask has run). 

    Tim

    • Marked as answer by Andrew_Zhu Wednesday, August 11, 2010 6:50 AM
    Tuesday, August 10, 2010 5:36 PM
  • Tim,

    thank you for this. But in that way class cannot be partial, must be derived from XAML defined class, otherwise compiler gives error about the same parameter constructor.

    thank you...


    dogu
    Wednesday, August 11, 2010 7:03 AM
  • Interesting. I still got compiling with the partial class. Maybe we're doing something just a little bit different. In case you want to keep comparing notes, that constructor is the only member I defined in the partial class, and I didn't add arguments or anything on the activity...

    Tim

    Wednesday, August 11, 2010 7:11 AM
  • I removed parameters result is same. anyway you guide the way and saved my time, thank you...


    dogu
    Wednesday, August 11, 2010 7:21 AM