-
Notifications
You must be signed in to change notification settings - Fork 227
Open
Description
Summary
When you build a workflow using CoreWF and use C# code inside it (like for variables or loops), if that C# code needs the Match type (which comes from Regular Expressions/Regex), the workflow fails to compile and run on .NET 8.
The Error You See:
You get a System.InvalidOperationException, and inside that, many CS1069 errors saying something like: "The type name 'Match' could not be found in the namespace 'System.Text.RegularExpressions'". The error also hints that the Match type has been "forwarded" (moved) to a different library called System.Text.RegularExpressions.dll in .NET 8.
Environment:
- CoreWF version: 6.0.3
- .NET version: 8.0
- OS: Windows 11
- Context: Using CoreWF within a Visual studio community 2022
Steps to Reproduce:
- Create a custom NativeActivity using C# that returns IEnumerable<System.Text.RegularExpressions.Match> (see Matches code below).
- Create a XAML workflow using C# expressions.
- Define the System.Text.RegularExpressions namespace in XAML pointing to assembly=System (as shown in the sample XAML).
- Declare a variable or argument of type IEnumerablestr:Match.
- Use the custom activity and assign its output to that variable.
- Use a ForEachstr:Match loop to iterate over the results.
- Attempt to load or run the workflow.
Custom Activity Code (Matches.cs):
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.RegularExpressions;
public class Matches : NativeActivity
{
[RequiredArgument]
public InArgument<string> Input { get; set; }
[RequiredArgument]
public InArgument<string> Pattern { get; set; }
[Category("RegexOptions")]
public bool Compiled { get; set; } = true;
[Category("RegexOptions")]
public bool IgnoreCase { get; set; } = true;
public OutArgument<IEnumerable<Match>> Results { get; set; }
protected override void Execute(NativeActivityContext context)
{
var options = RegexOptions.None;
if (Compiled) options |= RegexOptions.Compiled;
if (IgnoreCase) options |= RegexOptions.IgnoreCase;
var result = new List<Match>();
// Regex.Matches comes from System.Text.RegularExpressions assembly
var ma = Regex.Matches(Input.Get(context), Pattern.Get(context), options);
foreach (Match m in ma) result.Add(m);
Results.Set(context, result);
}
}
Workflow XAML (Workflow.xaml):
<Activity mc:Ignorable="sap sap2010 sads" x:Class="WorkflowTest.Workflow1"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
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:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:str="clr-namespace:System.Text.RegularExpressions;assembly=System"
xmlns:u="clr-namespace:UtilitiesActivity;assembly=UtilitiesActivity"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="res" Type="OutArgument(scg:IEnumerable(str:Match))" />
</x:Members>
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
<sap2010:WorkflowViewState.IdRef>WorkflowTest.Workflow1_1</sap2010:WorkflowViewState.IdRef>
<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>AFusion.Rpa.Activity.Http</AssemblyReference>
<AssemblyReference>Microsoft.CSharp</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Activities</AssemblyReference>
<AssemblyReference>System.Configuration</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.Runtime.Serialization</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
<AssemblyReference>System.Xaml</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
<AssemblyReference>System.Xml.Linq</AssemblyReference>
<AssemblyReference>WindowsBase</AssemblyReference>
<AssemblyReference>PioneerActivity</AssemblyReference>
<AssemblyReference>UtilitiesActivity</AssemblyReference>
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>WorkflowTest</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<Sequence sap2010:WorkflowViewState.IdRef="Sequence_1">
<Sequence.Variables>
<Variable x:TypeArguments="x:String" Name="export" />
</Sequence.Variables>
<u:Matches Compiled="True" sap2010:WorkflowViewState.IdRef="Matches_3" IgnoreCase="True" Input="hello" Pattern="%[a-z]">
<u:Matches.Results>
<OutArgument x:TypeArguments="scg:IEnumerable(str:Match)">
<mca:CSharpReference x:TypeArguments="scg:IEnumerable(str:Match)">res</mca:CSharpReference>
</OutArgument>
</u:Matches.Results>
</u:Matches>
<ForEach x:TypeArguments="str:Match" DisplayName="ForEach<Match>" sap2010:WorkflowViewState.IdRef="ForEach`1_2">
<ForEach.Values>
<InArgument x:TypeArguments="scg:IEnumerable(str:Match)">
<mca:CSharpValue x:TypeArguments="scg:IEnumerable(str:Match)">res</mca:CSharpValue>
</InArgument>
</ForEach.Values>
<ActivityAction x:TypeArguments="str:Match">
<ActivityAction.Argument>
<DelegateInArgument x:TypeArguments="str:Match" Name="item" />
</ActivityAction.Argument>
<WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1">
<InArgument x:TypeArguments="x:String">
<mca:CSharpValue x:TypeArguments="x:String">item.Value</mca:CSharpValue>
</InArgument>
</WriteLine>
</ActivityAction>
</ForEach>
<Delay Duration="00:00:10" sap2010:WorkflowViewState.IdRef="Delay_1" />
<sads:DebugSymbol.Symbol>d0VDOlxVc2Vyc1xodW5naG5cRG9jdW1lbnRzXFJQQVxXb3JrZmxvd1Rlc3RcV29ya2Zsb3dUZXN0XFdvcmtmbG93LnhhbWwLMgNQDgIBATYFPBECAQ09BU0PAgEETgVOTAIBAjZkNmsCARI5CzlmAgEPNnQ2fAIBDkALQF4CAQpHCUsVAgEFThVOHwIBA0kNSVUCAQY=</sads:DebugSymbol.Symbol>
</Sequence>
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="Matches_3" sap:VirtualizedContainerService.HintSize="287,22" />
<sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="210,62" />
<sap2010:ViewStateData Id="ForEach`1_2" sap:VirtualizedContainerService.HintSize="287,212" />
<sap2010:ViewStateData Id="Delay_1" sap:VirtualizedContainerService.HintSize="287,22" />
<sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="309,460">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</sap2010:ViewStateData>
<sap2010:ViewStateData Id="WorkflowTest.Workflow1_1" sap:VirtualizedContainerService.HintSize="349,540" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>
Full Error Log:
System.InvalidOperationException: 'Compilation failures occurred:
Line 259: (260,89): error CS1069: The type name 'Match' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
Line 321: (322,89): error CS1069: The type name 'Match' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
... (rest of the CS1069 errors) ...
Line 0: warning CS1701: Assuming assembly reference 'System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'System.Activities' matches identity 'System.Linq.Expressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.Linq.Expressions', you may need to supply runtime policy
... (other CS1701 warnings) ...
Line 0: Unable to load assembly 'System.ServiceModel'.
Line 0: Unable to load assembly 'System.ServiceModel.Activities'.
Line 0: Unable to load assembly 'WorkflowTest'.
Complete results are contained in the Data property of this exception. Please correct the errors in the source and retry the Load.'
Metadata
Metadata
Assignees
Labels
No labels
