Cannot find Main method using reflection with .NET 5 top level calls
问题 var pt = Type.GetType("<Program>$"); var m = pt.GetMethod("<Main>$", BindingFlags.Static); // m is null Okay, I grab the Program class, this works fine. But when I go to grab the Main method, system cannot find it, and it's not in pt.GetMembers() either. What's going on? 回答1: You just need to specify that you want to see non-public members: using System; using System.Reflection; var pt = Type.GetType("<Program>$"); var m = pt.GetMethod("<Main>$", BindingFlags.Static | BindingFlags.NonPublic);