反射的问题

Yang_Wenli 2002-05-09 10:28:00
为什么出错?

Type t = Type.GetType("System.Windows.Forms.Button", true);

如果
Type t = Type.GetType("System.Windows.Forms.Button");
则t为null

怎么解决?
...全文
76 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinchy 2003-01-02
  • 打赏
  • 举报
回复
x
qqchen79 2002-05-10
  • 打赏
  • 举报
回复
sorry, 看来GAC里面的assembly只能使用全名来引用了:
string aname = "System.Windows.Forms.Button, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
Type t = Type.GetType(aname, true);
Yang_Wenli 2002-05-09
  • 打赏
  • 举报
回复
To:qqchen79(知秋一叶)

还是出错
未处理的“System.IO.FileNotFoundException”类型的异常出现在 WindowsApplication3.exe 中

其他信息:找不到文件或程序集名称“System.Windows.Forms”,或找不到它的一个依赖项。
qqchen79 2002-05-09
  • 打赏
  • 举报
回复
参数应该是full qualified typename。用这个:
Type.GetType("System.Windows.Forms.Button, System.Windows.Forms");
true加不加都没关系。
Yang_Wenli 2002-05-09
  • 打赏
  • 举报
回复
自己定义的类可以,就连System.Int32等都可以,但是System.Windows.Forms.Button就不可以,不过我恰巧要用System.Windows.Forms.Button。
yuechang 2002-05-09
  • 打赏
  • 举报
回复
用第一个就会报"未能从程序集 WindowsApplication1, Version=1.0.859.19452, Culture=neutral, PublicKeyToken=null 中加载类型 System.Windows.Forms.Button。"
你不报错当然就是null了.你可以自己定义一个类型再试一下.
acptvb 2002-05-09
  • 打赏
  • 举报
回复
感谢您使用微软产品。

可以通过如下两种方式来实现您的目的:
(1)在VC#中使用typeof:
Type myTypeBindingFlags = typeof(System.Windows.Forms.Button);
(2)第二中方法是:
using System.Reflection;
……
Assembly assembly=null;
assembly = Assembly.LoadFrom("C:\\WINNT\\Microsoft.NET\\Framework\\v1.0.3705\\System.Windows.Forms.dll");
Type tt = assembly.GetType("System.Windows.Forms.Button", true);
希望这些信息对你有帮助。

— 微软全球技术中心 VB支持中心

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
lonk 2002-05-09
  • 打赏
  • 举报
回复
你用typeof吧,
Type t=typeof(System.Windows.Forms.Button);
...
Yang_Wenli 2002-05-09
  • 打赏
  • 举报
回复
UP

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧