Switch from VB to C# in Workflow Designer
Asked Answered
M

2

5

I'm creating an Activity Library in Visual Studio 11 Beta (although I've repeated all my steps in VS2010 with the same result), targeting the .NET 4.0 framework.

As I started entering arguments via the Workflow Designer, I noticed the "Enter a VB Expression" message in the Default Value box. I'm not sure how to change the language context from VB to C#.

To create the project, I followed these steps:

  1. Go to File> New and select Project...

  2. In the Installed> Templates section of the New Project dialog window, select Visual C#> Workflow> Activity Library

  3. Name the project, as usual, and click OK

And that's basically it. I noticed then that the default Activity1.xaml file was expecting VB in the default values fields. I deleted it and then followed these steps to create a new Activity:

  1. Right-click on the project and select Add> New Item...

  2. In the Add New Item dialog window, navigate to Installed> Visual C# Items> Workflow> Activity

  3. Name the Activity and click OK

It was the same result, the Default Value fields are expecting a VB expression.

When I look at the XAML code, I can clearly see the Microsoft.VisualBasic.Activities namespace listed and a VisualBasic.Settings element, but I'm not sure what to do to change it; everytime I try, I just end up screwing things up. Here's the XAML code being generated:

<Activity mc:Ignorable="sads sap" x:Class="THINKImport.CustomerAddOrderAdd"
 xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
 xmlns:local="clr-namespace:THINKImport.THINKWebReference"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
 xmlns:s="clr-namespace:System;assembly=System.Core"
 xmlns:s1="clr-namespace:System;assembly=System"
 xmlns:s2="clr-namespace:System;assembly=System.ServiceModel"
 xmlns:s3="clr-namespace:System;assembly=mscorlib"
 xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
 xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
 xmlns:t="clr-namespace:THINKImport"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
    <x:Property Name="user_login_data" Type="InArgument(local:user_login_data)" />
    <!--Removed the other properties for brevity-->
  </x:Members>
  <sap:VirtualizedContainerService.HintSize>440,440</sap:VirtualizedContainerService.HintSize>
  <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
</Activity>
Madras answered 31/5, 2012 at 15:46 Comment(0)
C
5

C# Expressions

Previously, all expressions in workflows can only be written in Visual Basic. In .NET Framework 4.5 RC, Visual Basic expressions are only used for projects created using Visual Basic. Visual C# projects now use C# for expressions. A fully functional C# expression editor is provided which capabilities such as grammar highlighting and intellisense. C# workflow projects created in previous versions that use Visual Basic expressions will continue to work.

As of Beta 1, C# expressions are validated at design-time. Errors in C# expressions will be marked with a red wavy underline.

More: What's New in Windows Workflow Foundation in .NET 4.5

Curiosity answered 1/6, 2012 at 1:43 Comment(0)
M
6

I was able to figure out the issue.

First, though, I was able to discover the root cause here. In a nutshell, it says VB.NET must be used in the Expression Editor even if the program is in C#.

So, I was kinda bummed about that, but I decided to take another crack at the XAML code because, in working through the WF tutorials, there was most definitely an activity I was working on in the designer that would accept Expressions in C#. I opened up that project and went through the XAML code.

It's then that I noticed this line:

<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>

I searched the MSDN library and found the documentation for the ExpressionActivityEditor class. As best as I can tell, this is new to .NET 4.5. In my particular case, there isn't any reason I can't target .NET 4.5 in my project, so I changed it. Once the solution reopened, right away, all the Expression Editor text fields and boxes would accept C#. In order to "start fresh", I deleted the activity file I had been working on and created a new one. If anyone's interested, here's that generated XAML code:

<Activity mc:Ignorable="sap sap2010 sads" x:Class="THINKImport.CustomerAddOrderAdd"
      xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
      xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
      xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
      xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:THINKWebReference="clr-namespace:THINKImport.THINKWebReference">
  <x:Members>
  <x:Property Name="user_login_data" Type="InArgument(THINKWebReference:user_login_data)">
    <x:Property.Attributes>
      <RequiredArgumentAttribute />
        </x:Property.Attributes>
    </x:Property>
    <x:Property Name="customer_data" Type="InArgument(THINKWebReference:customer_data)" />
    <!--Remainder of Properties removed for brevity-->
  </x:Members>
  <sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
  <TextExpression.NamespacesForImplementation>
    <sco:Collection x:TypeArguments="x:String">
      <x:String>System</x:String>
      <x:String>System.Collections.Generic</x:String>
      <x:String>System.Data</x:String>
      <x:String>System.Linq</x:String>
      <x:String>System.Text</x:String>
    </sco:Collection>
  </TextExpression.NamespacesForImplementation>
  <TextExpression.ReferencesForImplementation>
    <sco:Collection x:TypeArguments="AssemblyReference">
      <AssemblyReference>mscorlib</AssemblyReference>
      <AssemblyReference>System</AssemblyReference>
      <AssemblyReference>System.Core</AssemblyReference>
      <AssemblyReference>System.Data</AssemblyReference>
      <AssemblyReference>System.ServiceModel</AssemblyReference>
      <AssemblyReference>System.Xml</AssemblyReference>
    </sco:Collection>
  </TextExpression.ReferencesForImplementation>
  <sap2010:WorkflowViewState.IdRef>
    THINKImport.CustomerAddOrderAdd_1
  </sap2010:WorkflowViewState.IdRef>
  <sap2010:WorkflowViewState.ViewStateManager>
    <sap2010:ViewStateManager>
      <sap2010:ViewStateData Id="THINKImport.CustomerAddOrderAdd_1" sap:VirtualizedContainerService.HintSize="440,440" />
    </sap2010:ViewStateManager>
  </sap2010:WorkflowViewState.ViewStateManager>
</Activity>

So, quite a bit different (to me, anyways) but I can use C# now, so I'm happy.

Madras answered 31/5, 2012 at 19:47 Comment(0)
C
5

C# Expressions

Previously, all expressions in workflows can only be written in Visual Basic. In .NET Framework 4.5 RC, Visual Basic expressions are only used for projects created using Visual Basic. Visual C# projects now use C# for expressions. A fully functional C# expression editor is provided which capabilities such as grammar highlighting and intellisense. C# workflow projects created in previous versions that use Visual Basic expressions will continue to work.

As of Beta 1, C# expressions are validated at design-time. Errors in C# expressions will be marked with a red wavy underline.

More: What's New in Windows Workflow Foundation in .NET 4.5

Curiosity answered 1/6, 2012 at 1:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.