Possible Duplicate:
Are automatically generated GUIDs for types in .NET consistent?
I want to use Type
as a key dictionary, but I'd rather use either full type name or Type.GUID
. How reliable and correct is Type.GUID
for this task?
Ayende Rahien writes:
Can you rely on System.Type.GUID to be stable?
By stable I mean that it will generate the same value for the same type across compilations. Empirical evidence suggest that this is the case, with the following factors determining the Guid of a type:
- Type name (including the namespace)
- Assembly name
- Assembly public key
Reflectoring into the system, it turns out that System.Type.GUID is eventually translated to a call to System.RuntimeType.GetGUID, this is one of the scary InternallCall method that are implemented directly in the runtime itself.
I wonder...
Don't use it.
typeof(byte).GUID
00000000-0000-0000-0000-000000000000
typeof(int).GUID
00000000-0000-0000-0000-000000000000
typeof(short).GUID
00000000-0000-0000-0000-000000000000
Tested on ideone.com, they run Mono 2.8
EDIT: after using System.Reflection on various (big) assemblies I could not find a collision between two GUIDs. So it seems the 0-GUID issue is Mono-specific.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With