this is not the way to call a static method in a managed assembly, InteropServices is used to call unmanaged code, tryusing System;
using System.Reflection;class Test
{
public static void Main()
{
Assembly a = Assembly.LoadFrom("ClassLibrary1.dll");
Type t = a.GetType("Class1");
MethodInfo m = t.GetMethod("getNum",BindingFlags.Public | BindingFlags.Static);
if (m != null)
{
int i = (int)m.Invoke(null, new object[]{});
Console.WriteLine(i);
}
}
}
using System.Reflection;class Test
{
public static void Main()
{
Assembly a = Assembly.LoadFrom("ClassLibrary1.dll");
Type t = a.GetType("Class1");
MethodInfo m = t.GetMethod("getNum",BindingFlags.Public | BindingFlags.Static);
if (m != null)
{
int i = (int)m.Invoke(null, new object[]{});
Console.WriteLine(i);
}
}
}
解决方案 »
- c#winform制作升级包
- 从这个例子怎么看出静态方法好了
- 将已有文件下的全部类打成DLL
- 高手请指点一下,DataGridViewComboBoxColumn 选值的问题
- 大量数据需要提交到数据库,如何提高效率?
- 以下代码就是不能更新成功,不知道为什么?
- 新手入门,请教方法调用的问题,分不够可加
- Exception Management Application Block模块中设定配置文件来设置Customer Pulishers不起作用!
- Threading.Timer线程终止现象解析
- C# 如何使用cookie进行自动登录
- 如何给程序添加上版本信息?
- 怎么建立一个内存graphics画好一个图片再拷到你的窗口画面?
估计你的程序还会报错,报个"未实例化的错误".