The following code snippet fails:
Unhandled exception: System.MissingMethodException: method TestApp.Example.Value not found.
I also tried changing BindingFlags.Static to BindingFlags.Instance and passing the actual instance as the fourth parameter, but with the same results. Is there any way to fix this?
using System.Reflection; namespace TestApp { class Program { static void Main() { var flags = BindingFlags.GetProperty | BindingFlags.Static | BindingFlags.Public; var value = typeof(Example).InvokeMember("Value", flags, null, null, null); } } public sealed class Example { public static readonly string Value = "value"; } }
source share