locked
"significant whitespace" build errors in workflows with custom designers (with attached sample project) RRS feed

  • Question

  • I'm using some custom designers in a workflow and occasionally get a combo of errors that don't make much sense.

    On the designer surface, the following error is shown:

    Cannot create unknown type '{clr-namespace:HurrDurr.Activities}MyActivity'.
    System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:HurrDurr.Activities}MyActivity'.
       at System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
       at blah blah yadda yadda...

    In the error list, I get the following error:

    Error 1 XC1020: Build error occurred in the XAML MSBuild task: 'The value ' ' contains significant white space(s) but "xml:space = preserve" cannot be written down on the member '{clr-namespace:HurrDurr.Activities;assembly=HurrDurr}MyActivity.Variables'.'

    So the designer says the type is unknown, and the error list says I have some issue with significant whitespace.  Except I don't, or cannot find it.


    EDIT
    I've got a sample project that shows the bug

    http://cid-f8be9de57b85cc35.skydrive.live.com/self.aspx/Public/SignificantWhitespaceBug.zip

    and a bug report

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=512240

    EDIT2
    By removing any whitespace in the identified section (MyActivity.Variables) I can get it to compile.
    Thursday, November 19, 2009 1:55 PM

Answers

  • The issue seems to have been fixed post beta2. I have sent you the Xaml generated now. Please let us know if that is not the Xaml you got.

    Thanks,
    Kushal.
    Kushal Shah - This posting is provided "AS IS" with no warranties, and confers no rights
    • Marked as answer by Will Sullivan Friday, November 20, 2009 7:57 PM
    Friday, November 20, 2009 7:05 PM
  • I checked on the Beta2 bits and the issue does repro there while on the latest bits things are fine.

    So, certainly this should be fine in the RTM timeframe for you.

    Thanks,
    Kushal.
    Kushal Shah - This posting is provided "AS IS" with no warranties, and confers no rights
    • Proposed as answer by kushals Monday, November 23, 2009 8:59 PM
    • Marked as answer by Will Sullivan Tuesday, November 24, 2009 1:51 PM
    Monday, November 23, 2009 8:59 PM

All replies

  • The issue seems to have been fixed post beta2. I have sent you the Xaml generated now. Please let us know if that is not the Xaml you got.

    Thanks,
    Kushal.
    Kushal Shah - This posting is provided "AS IS" with no warranties, and confers no rights
    • Marked as answer by Will Sullivan Friday, November 20, 2009 7:57 PM
    Friday, November 20, 2009 7:05 PM
  • I checked on the Beta2 bits and the issue does repro there while on the latest bits things are fine.

    So, certainly this should be fine in the RTM timeframe for you.

    Thanks,
    Kushal.
    Kushal Shah - This posting is provided "AS IS" with no warranties, and confers no rights
    • Proposed as answer by kushals Monday, November 23, 2009 8:59 PM
    • Marked as answer by Will Sullivan Tuesday, November 24, 2009 1:51 PM
    Monday, November 23, 2009 8:59 PM
  • I got the same exception, not very clear about the solution.

    I create an empty project, copy $TeamProject\BuildProcessTemplates\DefaultTemplate.xaml into the project, compile the project and got this excpetion.

    Could you provide me the solution or a workaround?

    thanks!
    Roger
    Monday, December 21, 2009 1:45 PM
  • Hello, 

    Could you please post the solution here?? 

    I have VS2010 Beta 2. 

    I am having the same issue and there virtually no information about this issue.

    Thanks
    Friday, January 15, 2010 12:11 PM
  • Say you have the following valid xml (namespace definitions removed for space reasons):
    <Activity>
      <x:Members>
        <x:Property Name="list" Type="InArgument(s:Int32[])" />
      </x:Members>
      <mva:VisualBasic.Settings>HURRDURRWTH</mva:VisualBasic.Settings>
      <local:MyActivity>
        <local:MyActivity.Variables>
          <Variable x:TypeArguments="x:Object" Name="current" />
          <Variable x:TypeArguments="scg3:KeyValuePair(x:String, x:Object)" Name="destination" />
        </local:MyActivity.Variables>
      </local:MyActivity>
    </Activity>
    Seems perfectly valid, right? So you try to compile and get the following exception:

    XC1020: Build error occurred in the XAML MSBuild task: 'The value ' ' contains significant white space(s) but "xml:space = preserve" cannot be written down on the member '{clr-namespace:SignificantWhitespaceBug.Activities;assembly=SignificantWhitespaceBug}MyActivity.Variables'.

    Read what it's saying...  The XAML msbuild task is reading your xml and sees whitespace:  "The value ' '".  The task thinks that this is significant whitespace, so it tries to add the attribute "xml:space=preserve" on the node that contains the significant whitespace.  Normally, that would be no issue.  But this isn't XML, its XAML.  And the node that the MSBuild task is attempting to alter is "local:MyActivity.Variables".  This is not just an XML node, it has special meaning in XAML, it is a Property Element.  In xaml, you are not allwed to place ANY attribute on a property element.

    So, on the one hand, you have the MSBuild task trying to alter the property element to add an attribute, and you have the xaml compiler blowing the f up because of it.

    This bug has been fixed for the RC.

    The only way to fix it in B2 is to do the following:

    1) Read the error.  This tells you the xml node that is the target of the MSBuild task bug (in this case, MyActivity.Variables)
    2) Remove all significant whitespace within this element:

    <Activity>
      <x:Members>
        <x:Property Name="list" Type="InArgument(s:Int32[])" />
      </x:Members>
      <mva:VisualBasic.Settings>HURRDURRWTH</mva:VisualBasic.Settings>
      <local:MyActivity>
        <local:MyActivity.Variables><Variable x:TypeArguments="x:Object" Name="current" /><Variable x:TypeArguments="scg3:KeyValuePair(x:String, x:Object)" Name="destination" /></local:MyActivity.Variables>
      </local:MyActivity>
    </Activity>

    Now, the problem most of you are having is that you're adding variables in code in an attempt to configure your activity before adding it to the workflow.  This is wrong:

    public MyActivity()
    {
        ResultVariable = new Variable<Dictionary<string, object>>("resultVariable",new Dictionary<string, object>());
        Current = new Variable<object>("current");
        Destination = new Variable<KeyValuePair<string, object>>("destination");
        Variables.Add(Current);
        Variables.Add(Destination);
    }
    This is wrong.  You need to create an activity factory for this:

    public sealed class MyActivity : IActivityTemplateFactory
    {
        public System.Activities.Activity Create(System.Windows.DependencyObject target)
        {
            return new MyActivityActivity()// renamed the original activity; the factory goes in the toolbox
            {
                DisplayName = "MyActivityLol",
                Variables =
                {
                        new Variable<Dictionary<string, object>>("resultVariable",new Dictionary<string, object>()),
                        new Variable<object>("current"),
                        new Variable<KeyValuePair<string, object>>("destination")
                }
            };
        }
    }
    (There might be some bugs in that; not sure if it would work with the sample projects I posted).  Using an activity factory you avoid the bug altogether.  You can Bingle for information on how to create in/out/in-out arguments and variables within your activity factory.  There are some good posts out there about the subject now.
    Friday, January 15, 2010 2:42 PM
  • Added a workaround and a solution.
    Friday, January 15, 2010 2:43 PM
  • Hi Will,

    how do you solve this problem?

    i have the same horror...

    thanks for the help,

    Rui M.
    Monday, January 18, 2010 5:14 PM
  • I just posted a big long solution + a workaround.  Look up.
    Monday, January 18, 2010 7:30 PM
  • ok thanks
    Tuesday, January 19, 2010 10:11 AM
  • I just posted a big long solution + a workaround.  Look up.

    Thanks very much! I'm new to this, Could you give more details?
    Friday, October 8, 2010 3:05 AM
  • I just posted a big long solution + a workaround.  Look up.

    Thanks very much! I'm new to this, Could you give more details?
    Friday, October 8, 2010 3:10 AM