Fix STAThreadAttribute/MTAThreadAttribute on main entry point not respected by Native...
authorThomasGoulet73 <51839772+ThomasGoulet73@users.noreply.github.com>
Wed, 1 Jun 2022 08:19:37 +0000 (04:19 -0400)
committerGitHub <noreply@github.com>
Wed, 1 Jun 2022 08:19:37 +0000 (17:19 +0900)
Fixes dotnet/runtime#70066

src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs

index 2c91f88..435198b 100644 (file)
@@ -105,12 +105,12 @@ namespace Internal.IL.Stubs.StartupCode
             MethodDesc initApartmentState = startup?.GetMethod("InitializeApartmentState", null);
             if (initApartmentState != null)
             {
-                if (_mainMethod.HasCustomAttribute("System", "STAThreadAttribute"))
+                if (_mainMethod.WrappedMethod.HasCustomAttribute("System", "STAThreadAttribute"))
                 {
                     codeStream.EmitLdc((int)System.Threading.ApartmentState.STA);
                     codeStream.Emit(ILOpcode.call, emitter.NewToken(initApartmentState));
                 }
-                if (_mainMethod.HasCustomAttribute("System", "MTAThreadAttribute"))
+                if (_mainMethod.WrappedMethod.HasCustomAttribute("System", "MTAThreadAttribute"))
                 {
                     codeStream.EmitLdc((int)System.Threading.ApartmentState.MTA);
                     codeStream.Emit(ILOpcode.call, emitter.NewToken(initApartmentState));