Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Type.GUID uniquely identifies each type across compilations? [duplicate]

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...

like image 697
Tomislav Markovski Avatar asked Dec 29 '11 10:12

Tomislav Markovski


1 Answers

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.

like image 85
user703016 Avatar answered Oct 11 '22 13:10

user703016