Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting API - Operation is not supported on this platform. (when AOT published) #73689

Open
3HMonkey opened this issue May 24, 2024 · 0 comments
Assignees

Comments

@3HMonkey
Copy link

The goal is to create a simple test application that enables the loading of a script and accesses a predefined static class and outputs a value from this class to the console.

Version Used:
4.10.0-3.final

Steps to Reproduce:

I created a new net8 console application (puplish AOT profile) with basic project setup:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <InvariantGlobalization>true</InvariantGlobalization>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.10.0-3.final" />
  </ItemGroup>

</Project>

Added an additional class in RoslynTest.Test namespace to the project:

public static class Foo
{
    public static string Name { get; set; } = "Bar";
}

then the simple main task:

using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;

namespace RoslynTest
{
    internal class Program
    {
        static async Task Main(string[] args)
        {

            try
            {
                var codeToEval =
                @"
                int test = 0;
                var count = test + 15;
                count++;
                Console.WriteLine(count);
                
                Console.WriteLine(Foo.Name);
                

                ";

                var options = ScriptOptions.Default;
                
                options = options
                    .WithImports("System", "RoslynTest.Test")
                    .AddReferences("RoslynTest");
                
                var result = await CSharpScript.EvaluateAsync(codeToEval, options);
                
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();


        }
    }
}

When running in debug mode it works like expected, so output is:

16
Bar

Expected Behavior:

16
Bar

Actual Behavior:
When published using aot with params:

Configuration: Release
Deployment mode: Self-contained
Target runtime: win-x64

and running the application it throws an exeption:

Operation is not supported on this platform.

Diagnostic:

I identified by using outputs that the problem is with:

CSharpScript.EvaluateAsync(codeToEval, options);

Is there any workaround or a best practise for this?
Thx guys

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels May 24, 2024
@Cosifne Cosifne removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants