I'm writing a Durable Function and need to generate some GUIDs. According to the documentation, you need to take extra care with this because GUID generation is not deterministic. When the orchestration is replayed, it should use the same GUID, and the workaround described in the documentation is to
Use
NewGuid
in .NET ornewGuid
in JavaScript to safely generate random GUIDs.
I assume they mean the static method Guid.NewGuid()
, yet when I use it in my code, like this:
[FunctionName("Orchestration")]
public static async Task Orchestration([OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger) {
var guid = Guid.NewGuid();
I get a compiler warning:
Warning DF0102: 'Guid.NewGuid' violates the orchestrator deterministic code constraint. (DF0102)
and when I run the function, I see that it produces a different GUID when replaying, so it's definitely not deterministic. I know I can write an activity function to generate a GUID, but this seems a bit overkill if there's dedicated support for this. This GitHub comment mentions it has been released in v1.7.0 (I'm using v2.3.1).