Search code examples
.netwpfworkflow-foundation-4

Weird Exceptions from Visual Studio in Workflow Foundation project


I'm getting a "type or namespace name could not be found" exception when I try to create an instance of an activity. Target Framework is .Net4 (full profile)

The WF is defined as follows:

<Activity x:Class="MyApp.Workflow.MyWorkflow " ...>

It doesn't contain any activity code yet, just created it. My calling code:

using MyApp.Workflow;
MyWorkflow workflow = new MyWorkflow();

I made sure all dlls referenced in the workflow's xaml are referenced. Does anybody have an idea what else I could check?

EDIT - Tried the following :

  • Add a new Activity to the project
  • Go to any source code file and add a call to activity's constructor (with syntax highlighting and code completion - intellisense recognizes the type)
  • Recompile

Result: The Type of the Workflow (MyApp.Workflow.MyWorkflow) is unknown. When I do the same thing in another solution with exactly the same references, it works as it should.


Solution

  • OK, found it, eventually. There seems to be a bug in the XAML-parser that causes this to happen. It can easily be reproduced:

    • Create a WPF project
    • Add a WF Activity to that project and place a call to that activity's constructor somewhere
    • Press F6 and be happy
    • Add xmlns:xyz="clr-namespace:Namespace.That.Contains.Controls" to your Window's code. If you don't feel like creating controls, just use the namespace the window is defined in.
    • Press F6 and see how the activity can not be parsed anymore. If the activity is within a namespace that it spans, the namespace won't exist, otherwise the activity's type will not exist.

    GodDammit, that cost me an entire day...