4 ms·
> Plain old reflection that just works (why should it not?) I definitely don't fully understand the landscape, so I could certainly be wrong, but I assumed tha
by jborean93 3mo ago
> Plain old reflection that just works (why should it not?)
I definitely don't fully understand the landscape, so I could certainly be wrong, but I assumed that normal reflection didn't work in AOT because after trimming that method may or may not be there. If it was never called in a normal way then the compiler doesn't know that `Console.WriteLine` was being used as `GetMethod` may have a runtime value as a string rather than a constant value known at compile time. If the compiler didn't know it was being called then it will be trimmed out of the final binary whereas with `UnsafeAccessorAttribute` it provides the information required to not trim it.
Edit: I tried the following https://sharplab.io/#v2:D4AQTAjAsAUCAMACEEB0AlApgMwDaYGMAXASwHsA7AbllgoEMBbTAZwAd6DNEBBMogCqsiNGLBABmZGEQBhXPRYtoMAN6xEm5FJQA2ZABZEAWXokKAChTwA2gF1E9AE4BzFgEoNW9TC1/EJNiIFs5uqAAymBQuRAAWiACEALyIYJ6+/po+mZlxTmQA7ogUmEUAogAeXGyklBYAJABElWyEpNGpjq4sADSI2GQArhQAJoiqoSwRUTGxAL6N7qI5iHO0GZkCAJ6tiE44+MTkFNu7KaeYqADimII7mCHdNvB26St+APwfiHmFxaW8VyDZgUIiVaq1SxNABiZnwYyIZH65gR90QAHIJk8XnN0YtRF5MsZbrEyCMAJIUAaIZhxMmIFL7PBtY4Xa63Yl0kaPNw2CB2Po2Ij3MjYKwQeDuV6E95fH6xfJFEpFHhAkFgqqYGrHBqNWEkeE/JHYFE0kn0zGTPl2XH4mV+WmkkaoSkANzIAGsHhRBrhcILGkIWERELhzJhGq9ljkZWsYHGgA== https://sharplab.io/#v2:D4AQTAjAsAUCAMACEEB0AlApgMwDaYGMAXAS... and it fails when I provide the type and method for Console.WriteLine as arguments. If I was to add `typeof(Console).GetMethod(args[1], [typeof(string)])!.Invoke(null, ["dummy"]);` to it before the `Type.GetType` call it seems to be enough to not trim out the `Console` type and the `WriteLine` method. The compiler seems to at least be smart that way.