UiPath / CoreWF

WF runtime ported to work on .NET 6
MIT License
1.13k stars 214 forks source link

CSharpValue and CSharpReference are not fully functional yet #48

Closed ewinnington closed 4 years ago

ewinnington commented 5 years ago

When working on Xaml workflows generated by visual studio with CSharpValue and CSharpReference elements, I get a Workflow not compiled error even after setting compilation to true in the settings.

I’ll try and resolve this down to a simple test case, the WF I built was too ambitious.

Has anyone else managed to use a Visual Studio defined Xaml Workflow?

Also with the assembly name change, you have to change the Xaml declaration at the beginning of the Xaml to make it work.

This is related to my testing this in my wfRunnerCore repo.

Related to #7

ewinnington commented 5 years ago

Workflow code in C# Expressions (generated by Visual Studio) fails with the message: Expression Activity type 'CSharpReference`1' requires compilation in order to run. Please ensure that the workflow has been compiled.

Of course, the xaml was loaded with compilation activated (new ActivityXamlServicesSettings { CompileExpressions = true });)

XAML from Generated from Visual Studio as a file Activity1.xaml :

<Sequence>
    <Sequence.Variables>
      <Variable x:TypeArguments=""x:Int32"" Name=""myInt"" />
    </Sequence.Variables>
    <Assign>
      <Assign.To>
        <OutArgument x:TypeArguments=""x:Int32"">
          <mca:CSharpReference x:TypeArguments=""x:Int32"">myInt</mca:CSharpReference>
        </OutArgument>
      </Assign.To>
      <Assign.Value>
        <InArgument x:TypeArguments=""x:Int32"">5</InArgument>
      </Assign.Value>
    </Assign>
    <WriteLine>
      <InArgument x:TypeArguments=""x:String"">
        <mca:CSharpValue x:TypeArguments=""x:String"">myInt.ToString()</mca:CSharpValue>
      </InArgument>
    </WriteLine>
    </Sequence>

The same Workflow code in expressed using the VB Expressions works:

<Sequence>
    <Sequence.Variables>
      <Variable x:TypeArguments=""x:Int32"" Name=""myInt"" />
    </Sequence.Variables>
    <Assign>
      <Assign.To>
        <OutArgument x:TypeArguments=""x:Int32"">[myInt]</OutArgument>
      </Assign.To>
      <Assign.Value>
        <InArgument x:TypeArguments=""x:Int32"">5</InArgument>
      </Assign.Value>
    </Assign>
    <WriteLine>
      <InArgument x:TypeArguments=""x:String"">[myInt.ToString()]</InArgument>
    </WriteLine>
  </Sequence>

The ActivityXamlServices Compile() routine is #if NET45, so the compilation does nothing currently. See https://github.com/UiPath/corewf/blob/master/src/CoreWf/XamlIntegration/ActivityXamlServices.cs#L266

Uncommenting the #if NET45 and following the code along brings me to the function TextExpressionCompilerResults CompileInMemory() which created a Microsoft.CSharp.CSharpCodeProvider and calls CompileAssemblyFromDom which returns System.PlatformNotSupportedException: 'Operation is not supported on this platform.'

Following down the chain leads me to this file in CoreFX https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.PlatformNotSupported.cs

 internal sealed partial class CSharpCodeGenerator
    {
        private CompilerResults FromFileBatch(CompilerParameters options, string[] fileNames)
        {
            throw new PlatformNotSupportedException();
        }
    }

So it seems that for this to work, we either need to remove the compilation flag check that gets us into this pathway, so that Roslyn can compile at execution time, or call into Roslyn during xaml loading.

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.