Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are automatically generated GUIDs for types in .NET consistent?

Tags:

Are the automatically generated GUIDs for C# Types consistent? For example, if I get a GUID for my interface, IFoo (typeof(IFoo).GUID), the first time a run the program, will I get that same GUID everytime I run the program?

I have tested it locally on my machine, and it seems to always be the same, but I'm not sure if I can rely on it always being the same across machines.

like image 914
blachniet Avatar asked Apr 13 '11 13:04

blachniet


1 Answers

See: System.Type.GUID stability. It appears that the current implementation of the method relies an internal call that is implemented by the CLR itself. Unless Microsoft clarifies the contracts for the auto-generated Guids (the Type.GUID documentation is currently silent on this issue), I wouldn't rely on the observed behaviour. To be sure about consistency, I recommend explicitly decorating the types in question with the GuidAttribute.

like image 110
Ani Avatar answered Oct 04 '22 01:10

Ani