Hello,
Can someone explain the following:
I'm trying to use Type.GetType that takes a string parameter which specifies
the type and assembly. For example:
Type t = Type.GetType("System.Drawing.Point, System.Drawing");
My issue is that unless I have System.Drawing.dll in the same directory as
my app, this call fails. I did a gacview to confirm that System.Drawing is
in the GAC. Why cant System.Drawing be loaded from the GAC?
I have similar issues doing:
Activator.CreateInstance("System.Drawing", "System.Drawing.Point")
This call only works if System.Drawing is in the same directory as my app -
it cant get loaded from the GAC
Lloyd Dupont - 13 Oct 2004 01:59 GMT
excellent question!
I want the answer too :D
> Hello,
>
[quoted text clipped - 15 lines]
> This call only works if System.Drawing is in the same directory as my
> app - it cant get loaded from the GAC
Imran Koradia - 13 Oct 2004 03:14 GMT
For assemblies loaded from GAC, you need to provide the version, culture and
publickeytoken information for the runtime to correctly resolve the
assembly. (This excludes the mscorlib assembly per documentation).
This should work (framework version 1.1):
Type t =
Type.GetType("System.Drawing.Point,System.Drawing,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a")
Depending on the framework version, the Version and PublicKeyToken could be
different in your case. Also, depending on the culture setting of your
computer, the Culture could be different. Apply appropriate values and it
should work.
hope that helps..
Imran.
> Hello,
>
[quoted text clipped - 15 lines]
> This call only works if System.Drawing is in the same directory as my
> app - it cant get loaded from the GAC
Lloyd Dupont - 13 Oct 2004 04:34 GMT
where does this public TokenKey come from?
I mean how can I know it?
is it from the AssemblyName.KeyPair.PublicKey?
> For assemblies loaded from GAC, you need to provide the version, culture
> and publickeytoken information for the runtime to correctly resolve the
[quoted text clipped - 33 lines]
>> This call only works if System.Drawing is in the same directory as my
>> app - it cant get loaded from the GAC
Imran Koradia - 13 Oct 2004 05:15 GMT
> where does this public TokenKey come from?
> I mean how can I know it?
> is it from the AssemblyName.KeyPair.PublicKey?
Nope - you can get it from AssemblyName.GetPublicKeyToken (The public key is
a huge key - I think its 1024 bit value - not absolutely sure. public key
token is only the lat 8 bytes of the public key). The method returns an
array of bytes. The values are Hex values. The publickeytoken also appears
in the value returned by objType.AssemblyQualifiedName (which returns the
assembly name, culture, version and public key token). Here's how you can
convert the array of bytes to the value thats displayed by the
AssemblyQualifiedName property:
Dim bArray() As Byte = objType.Assembly.GetName.GetPublicKeyToken
Dim hexs(bArray.Length - 1) As String
Dim Result As New System.Text.StringBuilder
For i As Integer = 0 To bArray.Length - 1
If CInt(bArray(i)) < 16 Then
hexs(i) = "0" & Hex(bArray(i))
Else
hexs(i) = Hex(bArray(i))
End If
Result.Append(hexs(i))
Next
MessageBox.Show(Result.ToString.ToLower)
hope that helps..
Imran.
Girish Bharadwaj - 13 Oct 2004 12:47 GMT
Since, you know the Assembly, You can *potentially* use
Assembly.LoadWithPartialName() and use the Assembly reference to get the
required Type. Of course, its not recommended since there is a problem in
upgrades.
http://blogs.gotdotnet.com/suzcook/commentview.aspx/87646756-a94d-4c3a-a313-56c2
9a59b22d
has some more infomation about LoadWithPartialName.
So does this: http://blogs.msdn.com/junfeng/archive/2004/01/29/64250.aspx

Signature
Girish Bharadwaj
http://msmvps.com/gbvb
> Hello,
>
[quoted text clipped - 15 lines]
> This call only works if System.Drawing is in the same directory as my app -
> it cant get loaded from the GAC