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

[NativeAOT] The Finalize method is not preserved via reflection #72494

Closed
LakshanF opened this issue Jul 19, 2022 · 1 comment
Closed

[NativeAOT] The Finalize method is not preserved via reflection #72494

LakshanF opened this issue Jul 19, 2022 · 1 comment

Comments

@LakshanF
Copy link
Member

NativeAOT does not seem to keep the Finalize method.

Repro: Run the below code under AOT
Current Behavior: The program throws

Instantiated object
Finalize
Invoking Finalize
Unhandled Exception: EETypeRva:0x00347398(System.Reflection.MissingRuntimeArtifactException): This object cannot be invoked because no code was generated for it: 'MyApp.ExampleClass.Finalize()'.
   at System.Reflection.Runtime.MethodInfos.RuntimeNamedMethodInfo`1.GetUncachedMethodInvoker(RuntimeTypeInfo[], MemberInfo) + 0x113
   at System.Reflection.Runtime.MethodInfos.RuntimeMethodInfo.get_MethodInvoker() + 0xa1
   at System.Reflection.Runtime.MethodInfos.RuntimeMethodInfo.Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) + 0x34
   at MyApp.Program.M1() + 0x81
   at test1!<BaseAddress>+0x1f7570

Expected: The code to run without problems

using System.Reflection;
using System.Diagnostics;

namespace MyApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            M1();
        }

        public static void M1()
        {
            ExampleClass ex = new ExampleClass();
            MethodInfo method = typeof(ExampleClass).GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Instance);
            Debug.Assert(method!=null);
            Console.WriteLine(method.Name);
            Console.WriteLine("Invoking Finalize");
            method.Invoke(ex, null);
        }

    }

    public class ExampleClass
    {
        public ExampleClass()
        {
            Console.WriteLine("Instantiated object");
        }

        ~ExampleClass()
        {
            Console.WriteLine("Finalizing object");
        }
    }
}
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 19, 2022
@MichalStrehovsky
Copy link
Member

Not planned. Added it to the uber issue at #69919.

@MichalStrehovsky MichalStrehovsky closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants