Skip to content

AOT support for .NET #283

@rodrigovaras

Description

@rodrigovaras

It seems this library does not have AOT support, i tried a basic sample and the AOT tooling give me warnings and the generated exe throws an exception.
Tried a trivial 3 lines sample on a Console app:

var interpreter = new Interpreter();
var result = interpreter.Eval("8 / 2 + 2");
Console.WriteLine($"result:{result}");

The build give me this:

  Restored C:\Users\rodrigov\source\repos\AOTTest1\AOTTest1\AOTTest1.csproj (in 238 ms).
C:\Program Files\dotnet\sdk\7.0.300-preview.23179.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInfer
ence.targets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-po
licy [C:\Users\rodrigov\source\repos\AOTTest1\AOTTest1\AOTTest1.csproj]
  AOTTest1 -> C:\Users\rodrigov\source\repos\AOTTest1\AOTTest1\bin\Debug\net7.0\win-x64\AOTTest1.dll
  Generating native code
C:\Users\rodrigov\.nuget\packages\dynamicexpresso.core\2.16.0\lib\netstandard2.0\DynamicExpresso.Core.dll : warning IL2
104: Assembly 'DynamicExpresso.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libr
aries [C:\Users\rodrigov\source\repos\AOTTest1\AOTTest1\AOTTest1.csproj]
C:\Users\rodrigov\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.4\framework\System.Linq.Expressions.d
ll : warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings. [C:\Users\rodrigov\source\repos
\AOTTest1\AOTTest1\AOTTest1.csproj]
C:\Users\rodrigov\.nuget\packages\dynamicexpresso.core\2.16.0\lib\netstandard2.0\DynamicExpresso.Core.dll : warning IL3
053: Assembly 'DynamicExpresso.Core' produced AOT analysis warnings. [C:\Users\rodrigov\source\repos\AOTTest1\AOTTest1\
AOTTest1.csproj]
C:\Users\rodrigov\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.4\framework\Microsoft.CSharp.dll : wa
rning IL3053: Assembly 'Microsoft.CSharp' produced AOT analysis warnings. [C:\Users\rodrigov\source\repos\AOTTest1\AOTT
est1\AOTTest1.csproj]
     Creating library bin\Debug\net7.0\win-x64\native\AOTTest1.lib and object bin\Debug\net7.0\win-x64\native\AOTTest1.
  exp
  AOTTest1 -> C:\Users\rodrigov\source\repos\AOTTest1\AOTTest1\bin\Debug\net7.0\win-x64\publish\

When running it give me this:

C:\Users\rodrigov\source\repos\AOTTest1>AOTTest1\bin\Debug\net7.0\win-x64\publish\AOTTest1.exe
Hello, World!
Unhandled Exception: System.NotSupportedException: 'System.Func`1[System.Int32]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility
   at System.Reflection.Runtime.General.TypeUnifier.WithVerifiedTypeHandle(RuntimeConstructedGenericTypeInfo, RuntimeTypeInfo[]) + 0x166
   at System.Reflection.Runtime.General.TypeUnifier.GetConstructedGenericTypeWithTypeHandle(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0x3b
   at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x44c
   at System.Linq.Expressions.Compiler.DelegateHelpers.GetFuncType(Type[]) + 0xcf
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeNewDelegate(Type[]) + 0x1e0
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeDelegateType(Type[]) + 0xfc
   at System.Linq.Expressions.Expression.Lambda(Expression, String, Boolean, IEnumerable`1) + 0x2d3
   at System.Linq.Expressions.Expression.Lambda(Expression, Boolean, IEnumerable`1) + 0x33
   at System.Linq.Expressions.Expression.Lambda(Expression, ParameterExpression[]) + 0x28
   at DynamicExpresso.Lambda.<.ctor>b__3_0() + 0xfd
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode) + 0xfe
   at System.Lazy`1.ExecutionAndPublication(LazyHelper, Boolean) + 0x77
   at System.Lazy`1.CreateValue() + 0xd4
   at System.Lazy`1.get_Value() + 0x29
   at DynamicExpresso.Lambda.InvokeWithUsedParameters(Object[]) + 0x34
   at DynamicExpresso.Lambda.Invoke(IEnumerable`1) + 0x248
   at DynamicExpresso.Lambda.Invoke(Parameter[]) + 0x26
   at DynamicExpresso.Interpreter.Eval(String, Type, Parameter[]) + 0x4d
   at DynamicExpresso.Interpreter.Eval(String, Parameter[]) + 0x64
   at Program.<Main>$(String[]) + 0x9f
   at AOTTest1!<BaseAddress>+0x45fa37
   at AOTTest1!<BaseAddress>+0x45faca

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions