c# - Can't obtain an instance of Type class for a type not defined in the currently executing assembly -
How do I get an example of a type class for a type defined in the currently executed? In the assembly or mscorlib.dll ?
a) That is, I have defined a class type in someType assembly in CSharpSnapIn.dll , E: \ CSharpSnapIn.dll , but for some reason when I try to specify a full path to this assembly, I get an exception:
type = t = Type.GetType ( "SomeType, E: \\ CSharpSnapIn.dll"); // exeception b) I also tried entering CSharpSnapIn.dll in the currently running \ bin \ debug directory The application is, but I still get an exception:
type = t = Type.GetType ("someType, CSharpSnapIn.dll"); // exeception thanx
edit:
1) I declare another category type SomeType2 (inside CsharpSnapIn.dll ) and this time it worked:
Type.GetType ("someType2, CSharpSnapIn"); The difference between some type and someType2 is that some type implements an interface declared in the external assembly asmIn , But this should not be an exception reason, because CsharpSnapIn.dll is referred to as asmIn ?! 2)
Note that the assembly does not need to be loaded first, unless the assembly résolator can find it
< P> In other words, type . GateType () first loads an assembly and then creates a type example? 3)
can be found by the Assembly inquiry, so it will have to be in the bin directory according to your second example. If it is an assembly with a strong name, then you have to give all the details.
So you are saying that we can not specify a complete path (for assembly) using Type.GetType () , but its Instead of the assembly need to be in the bin directory?
You must first load the assembly:
type T = Assembly. Load (@ "e: \ CSharpSnapIn.dll") .GetType ("SomeNs.SomeType", true);
Comments
Post a Comment