为什么System.Type.GetType("System.Windows.Forms.TextBox") 返回null
而System.Type.GetType("System.Int32")可以?我想根据字符串创建一个对象
System.Type t=System.Type.GetType(str)
object o=System.Activator.CreateInstance(t)
但是str="System.Windows.Forms.TextBox"时t为什么为null?我应该怎样做?
而System.Type.GetType("System.Int32")可以?我想根据字符串创建一个对象
System.Type t=System.Type.GetType(str)
object o=System.Activator.CreateInstance(t)
但是str="System.Windows.Forms.TextBox"时t为什么为null?我应该怎样做?
Message="Could not load type 'System.Windows.Forms.TextBox' from assembly 'WindowsApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
Source="mscorlib"
TypeName="System.Windows.Forms.TextBox"翻了一下google,没有发现很直接的方法。
如果你用的是1.1的话,就把这个AssemblyName修改一下也就是说语法应该是
Type.GetType("你的类型名,你的类型所在的程序集名")
这个程序集的名称一定要是AssemblyName,而不是“System.Forms.Windows”之类的,原因就是这样还是找不到程序集;
System.Type t1=Assembly.GetAssembly(typeof(TextBox)).GetType("System.Windows.Forms.TextBox");System.Type t2=Assembly.LoadFile("C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.Windows.Forms.dll").GetType("System.Windows.Forms.TextBox");
可以得到Type,但是觉得都不好!