How to invoke static method from C# class without creating instance

c#

Solution

You are missing the `BindingFlags.Static` flag.

String s = (String) myService.InvokeMember("SomeMethod", BindingFlags.Static | BindingFlags.InvokeMethod  | BindingFlags.Public,
null, null, new object[] {"MyParam"}); 

Problem

I have code like this: ``` class Program { static void Main(string[] args) { Assembly myAsm = Assembly.LoadFile(@"c:\Some.dll"); Type myService = myAsm.GetType("SomeClass"); String s = (String) myService.InvokeMember("SomeMethod", BindingFlags.InvokeMethod | BindingFlags.Public, null, null, new object[] {"MyParam"}); } } ``` In Some.Dll there is public static Method SomeMethod with String param returning String but I get method missing Error...

Original source