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

Hello World doesn't work with reflection disabled in NAOT #14355

Open
Tracked by #13398
WhiteBlackGoose opened this issue Nov 19, 2022 · 5 comments
Open
Tracked by #13398

Hello World doesn't work with reflection disabled in NAOT #14355

WhiteBlackGoose opened this issue Nov 19, 2022 · 5 comments
Assignees
Labels
Area-AOT Everything related to AOT Feature Improvement
Milestone

Comments

@WhiteBlackGoose
Copy link

$ ./output/fs-hello-world
Unhandled Exception: EETypeRva:0x0037B3E0: TypeInitialization_Type_NoTypeAvailable
 ---> EETypeRva:0x0037B3E0: TypeInitialization_Type_NoTypeAvailable
 ---> EETypeRva:0x0037AA80: Reflection_Disabled

Repro steps

dotnet new console -n fs-hello-world -lang F# && cd fs-hello-world
dotnet publish \
-p:SelfContained=true \
-p:PublishAot=true \
-p:IlcDisableReflection=true \
-o ./output
./output/fs-hello-world

Program.fs:

printfn "Hello from F#"

Expected behavior

Prints hello world

Actual behavior

Unhandled Exception: EETypeRva:0x0037B3E0: TypeInitialization_Type_NoTypeAvailable
 ---> EETypeRva:0x0037B3E0: TypeInitialization_Type_NoTypeAvailable
 ---> EETypeRva:0x0037AA80: Reflection_Disabled
   at Internal.Reflection.RuntimeTypeInfo.GetMethodImpl(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) + 0x5a
   at System.Type.GetMethod(String, BindingFlags) + 0x5a
   at <StartupCode$FSharp-Core>.$Printf..cctor() + 0x4d
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x158
   Exception_EndOfInnerExceptionStack
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x253
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0x1b
   at Microsoft.FSharp.Core.PrintfImpl..cctor() + 0x9
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x158
   Exception_EndOfInnerExceptionStack
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x253
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0x1b
   at Microsoft.FSharp.Core.PrintfImpl.revToArray[T](Int32, FSharpList`1) + 0x36
   at Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.parseAndCreateFuncFactoryAux(FSharpList`1, String, Type, Int32&) + 0xbb
   at Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.parseAndCreateFunctionFactory() + 0xee
   at Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.GetCurriedPrinterFactory() + 0x38
   at Microsoft.FSharp.Core.PrintfModule.gprintf[a, TState, TResidue, TResult, TPrinter](FSharpFunc`2, PrintfFormat`4) + 0xac
   at <StartupCode$sandbox-1668861381>.$Program.main@() + 0x44
   at sandbox-1668861381!<BaseAddress>+0x228cc9
   at sandbox-1668861381!<BaseAddress>+0x228d3c
Aborted
  • debian 12
  • gcc (Debian 12.2.0-9) 12.2.0
  • Debian clang version 14.0.6
  • SDK 7.0.100
@En3Tho
Copy link
Contributor

En3Tho commented Nov 19, 2022

It's a problem of printf family specifically. Console.WriteLine should work. I belive there was a flag of some sort planned to F# 7 to generate reflection free code but I'm not sure I'm correct here.

@vzarytovskii
Copy link
Member

A good thing to track in our aot bucket

@ratsclub
Copy link

This is currently working on my machine:

$ dotnet publish -p:SelfContained=true -p:PublishAot=true -p:IlcDisableReflection=true -o ./output
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  fs-hello-world -> /tmp/fs-hello-world/bin/Debug/net6.0/linux-x64/fs-hello-world.dll
  fs-hello-world -> /tmp/fs-hello-world/output/

$ ./output/fs-hello-world
Hello from F#

$ dotnet --version
6.0.408

@KevinRansom KevinRansom self-assigned this Jun 1, 2023
@KevinRansom KevinRansom moved this from Not Planned to Planned in F# Compiler and Tooling Jun 1, 2023
@MichalStrehovsky
Copy link
Member

This is currently working on my machine:

PublishAot doesn't do anything on .NET 6 - it was introduced in .NET 7.

Note IlcDisableReflection is an unsupported switch: we have no intention to stop using reflection in the runtime repo. We fix the issues found by IlcDisableReflection if the reflection use is unnecessary/avoidable, but don't go to great lengths - we're fine Won't fixing these since the mode is unsupported and we have no plans to make it supported.

@charlesroddie
Copy link
Contributor

charlesroddie commented Sep 14, 2023

This would be fixed by:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AOT Everything related to AOT Feature Improvement
Projects
Status: Planned
Development

No branches or pull requests

7 participants