简体   繁体   中英

Error creating runtime object of type System.Drawing.Point

I want to create a object of type System.Drawing.Point at runtime, I tried to use the code below:

String typename = "System.Drawing.Point";
Type tp = Type.GetType(typename);
Object instance = Activator.CreateInstance(tp);

But I always get tp == null . But, for example if I use System.Double everything is ok.

Type.GetType will try to load the type from mscorlib. Use assembly-qualified name of the type.

String typename = "System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

Type tp = Type.GetType(typename);

You need to qualify the assembly in your type name , so

String typename = "System.Drawing.Point, System.Drawing";

will work (if System.Drawing.dll is referenced and loaded).

typeName

Type: System.String

The assembly-qualified name of the type to get. [..] If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM