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…
From the documentation at http://msdn.microsoft.com/en-us/library/system.type.guid.aspx.
The purpose of
Type.GUIDis to get the value associated with the class using[Guid("...")]. However, it also returns a guid when this attribute is not associated. The problem is where it gets this. A small test shows that the guid is stable. I checked the guid of a class, and verified that it changed when I renamed the class. When I renamed the class back, I got the original guid again. However, since these guids appear out of thin air, they shouldn’t be trusted to be stable over time, releases, framework versions, etc.