diff --git a/src/Test/TestCases.Workflows/XamlTests.cs b/src/Test/TestCases.Workflows/XamlTests.cs index e73a181d..4c63ec04 100644 --- a/src/Test/TestCases.Workflows/XamlTests.cs +++ b/src/Test/TestCases.Workflows/XamlTests.cs @@ -199,6 +199,53 @@ public void VisualBasic_ChangeCompiler() VisualBasicSettings.Default.CompilerFactory = references => new VbJitCompiler(references); } + [Theory] + [InlineData(null)] + [InlineData(typeof(object))] + public async Task VisualBasic_CompileAnonymousTypes(Type targetType) + { + SetupCompilation(out var location, out var namespaces, out var assemblyReferences); + string expressionText = "in_dt_OrderExport.AsEnumerable().Where(Function(row) row.Field(Of String)(\"Country\") = in_CountryName).GroupBy(Function(row) New With {Key .SKU = row.Field(Of String)(\"SKU\"), Key .ProductTitle = row.Field(Of String)(\"Product Title\")}).Select(Function(g) New With {Key .SKU = g.Key.SKU, Key .ProductTitle = g.Key.ProductTitle, Key .NetQTY = g.Sum(Function(row) row.Field(Of Decimal)(\"Net QTY\")), Key .SD = g.Sum(Function(row) row.Field(Of Decimal)(\"S-D\")), Key .Taxes = g.Sum(Function(row) row.Field(Of Decimal)(\"Taxes\"))})"; + + var compilationResult = await VisualBasicDesignerHelper.CreatePrecompiledValueAsync(targetType, expressionText, namespaces, assemblyReferences, location); + + Assert.Equal(typeof(IEnumerable), compilationResult.ReturnType); + } + + [Theory] + [InlineData(null)] + [InlineData(typeof(object))] + public async Task CSharp_CompileAnonymousTypes(Type targetType) + { + SetupCompilation(out var location, out var namespaces, out var assemblyReferences); + string expressionText = "in_dt_OrderExport.AsEnumerable().Where(row => row.Field(\"Country\") == in_CountryName).GroupBy(row => new { SKU = row.Field(\"SKU\"), ProductTitle = row.Field(\"Product Title\")}).Select(g => new{SKU = g.Key.SKU,ProductTitle = g.Key.ProductTitle,NetQTY = g.Sum(row => row.Field(\"Net QTY\")),SD = g.Sum(row => row.Field(\"S-D\")),Taxes = g.Sum(row => row.Field(\"Taxes\"))})"; + + var compilationResult = await CSharpDesignerHelper.CreatePrecompiledValueAsync(targetType, expressionText, namespaces, assemblyReferences, location); + + Assert.Equal(typeof(IEnumerable), compilationResult.ReturnType); + } + + private static void SetupCompilation(out ActivityLocationReferenceEnvironment location, out string[] namespaces, out AssemblyReference[] assemblyReferences) + { + var seq = new Sequence(); + IList errors = []; + location = new ActivityLocationReferenceEnvironment(); + WorkflowInspectionServices.CacheMetadata(seq, location); + location.Declare(new Variable("in_CountryName"), seq, ref errors); + location.Declare(new Variable("in_dt_OrderExport"), seq, ref errors); + namespaces = ["System", "System.Linq", "System.Data"]; + assemblyReferences = + [ + new AssemblyReference() { Assembly = typeof(string).Assembly }, + new AssemblyReference() { Assembly = typeof(DataTable).Assembly }, + new AssemblyReference() { Assembly = typeof(Enumerable).Assembly }, + new AssemblyReference() { Assembly = typeof(System.ComponentModel.TypeConverter).Assembly }, + new AssemblyReference() { Assembly = typeof(IServiceProvider).Assembly }, + new AssemblyReference() { Assembly = Assembly.Load("System.Xml.ReaderWriter") }, + new AssemblyReference() { Assembly = Assembly.Load("System.Private.Xml") } + ]; + } + private class ThrowingJitCompiler : JustInTimeCompiler { public override LambdaExpression CompileExpression(ExpressionToCompile compilerRequest) => throw new NotImplementedException(); diff --git a/src/UiPath.Workflow/Activities/ExpressionCompiler.cs b/src/UiPath.Workflow/Activities/ExpressionCompiler.cs index f7c5c7b1..086bae1c 100644 --- a/src/UiPath.Workflow/Activities/ExpressionCompiler.cs +++ b/src/UiPath.Workflow/Activities/ExpressionCompiler.cs @@ -43,11 +43,16 @@ protected static Type GetSystemType(ITypeSymbol typeSymbol, Assembly assembly) { if (namedTypeSymbol.IsGenericType) { - return assembly.GetType($"{namedTypeSymbol.ContainingNamespace}.{namedTypeSymbol.MetadataName}").MakeGenericType(namedTypeSymbol.TypeArguments.Select(t=> GetSystemType(t, GetAssemblyForType(t))).ToArray()); + return assembly.GetType($"{namedTypeSymbol.ContainingNamespace.ToDisplayString()}.{namedTypeSymbol.MetadataName}").MakeGenericType(namedTypeSymbol.TypeArguments.Select(t => GetSystemType(t, GetAssemblyForType(t))).ToArray()); + } + + if (namedTypeSymbol.IsAnonymousType) + { + return typeof(object); } } - return assembly.GetType($"{typeSymbol.ContainingNamespace}.{typeSymbol.MetadataName}"); + return assembly.GetType($"{typeSymbol.ContainingNamespace.ToDisplayString()}.{typeSymbol.MetadataName}"); } protected abstract Compilation GetCompilation(IReadOnlyCollection assemblies, IReadOnlyCollection namespaces);