I'm trying to work with Type.GetType() in a console app with code that goes like this:
private static string RevokeApp(string app)
{
Type t = Type.GetType("Factory.App1");
MethodInfo method = t.GetMethod("Revoke", BindingFlags.Static | BindingFlags.Public);
var result = method.Invoke(null, null);
return result.ToString(); ;
}
t returns null in all the ways I've tried. I suspect the type's name is where my problem is. I've found advice pertaining to code that builds to a dll but my code builds to an exe and What I've tried - assembly-specific naming etc. - doesn't seem to be working.
Namespace = "ConsoleApplication3"
Any help, advice or derisive. peals of laughter will be welcome
答案 0 :(得分:0)
//Know your assembly path.
var assembly= Assembly.LoadFile(@"C:\myDll.dll");
Type type = assembly.GetType("Factory.App1");
object obj = Activator.CreateInstance(type);