Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guid.NewGuid(); behind the scenes in .NET Core

Researching the subject yesterday, I found several interesting questions (such as this one) on how GUIDs are ultimately generated. In brief; it seems that Guid.NewGuid(); calls CoCreateGuid in the COM, which in turn calls UuidCreate in the Windows RPC (docs here and here).

I found myself wondering; How does this work when the OS is not Windows, such as might be the case with .NET Core, and does this affect the 'version' algorithm used to generate the GUID (which I understand is Version 4 on Windows)?

like image 425
Parrybird Avatar asked Jul 05 '17 11:07

Parrybird


1 Answers

On non-windows machines, .NET Core will use either uuid_create on BSD (which is "version 1") or libuuid's uuid_generate_random function on macOS and linux ("version 4").

The implementation for the replacement CoCreateGuid function can be found in CoreCLR's source code on GitHub.

like image 136
Martin Ullrich Avatar answered Sep 28 '22 09:09

Martin Ullrich