In v10, the AppContext switch NServiceBus.Core.Hosting.UseV2DeterministicGuid must be explicitly set to true to opt into the new DeterministicGuid (XxHash128-based). The default remains the legacy MD5-based algorithm. In v11, this should be flipped: XxHash128 becomes the default, and users who need to preserve their existing MD5-based host IDs must explicitly set the switch to false.
Motivation
- MD5 is a cryptographic hash that is unnecessarily expensive for generating deterministic GUIDs and can cause FIPS compliance issues (see the comment in
HostingComponent.Settings.cs:118).
- XxHash128 is non-cryptographic, faster, and produces well-distributed GUIDs with proper v8/RFC 9562 formatting.
- The new implementation has been available since v10 with an explicit opt-in. v11 is the right time to make it the default while still offering a backward-compatible escape hatch.
Changes Required
- Flip the
AppContextSwitches.UseV2DeterministicGuid default
In AppContextSwitches.cs, change the logic so that the switch defaults to true (use v2) unless explicitly set to false:
// Before (v10): returns true only when switch is explicitly enabled
state = AppContext.TryGetSwitch(UseV2DeterministicGuidSwitchName, out var isEnabled) && isEnabled
? SwitchState.Enabled
: SwitchState.Disabled;
// After (v11): returns true unless switch is explicitly disabled
state = AppContext.TryGetSwitch(UseV2DeterministicGuidSwitchName, out var isEnabled) && !isEnabled
? SwitchState.Disabled
: SwitchState.Enabled;
- Invert the warning in
HostingComponent.Initialize
The current warning tells users how to opt into v2. It should be inverted to warn users who are on the legacy path that they should migrate, and that the legacy class will be removed in v12.
- Rename the switch constant**
Consider renaming UseV2DeterministicGuidSwitchName to something like UseLegacyDeterministicGuidSwitchName (or keeping the old name as a compat alias) so the name reflects the new semantics: setting it to true means "use the old MD5 algorithm". Update the documentation strings, environment variable guidance, and UsedLegacyDeterministicGuidSettingsKey accordingly.
- Update
HostingComponent.Settings.GenerateHostId
Invert the branch: the default path uses DeterministicGuid.Create, and only when the switch explicitly opts into legacy does it use LegacyDeterministicGuid.Create.
- Update
PreObsolete on LegacyDeterministicGuid
The annotation already marks it for removal in v12 with DeterministicGuid as the replacement. No change needed there.
Breaking Change
This is a host ID breaking change for endpoints that do not explicitly set the switch. Endpoints that rely on the MD5-based host ID (e.g., for correlating with existing ServicePulse entries) will get a new host ID after upgrading unless they set:
AppContext.SetSwitch("NServiceBus.Core.Hosting.UseV2DeterministicGuid", false);
Or via environment variable (.NET 9+): DOTNET_NServiceBus_Core_Hosting_UseV2DeterministicGuid=false
Follow-up (v12)
Remove LegacyDeterministicGuid and the AppContext switch entirely.
References
src/NServiceBus.Core/AppContextSwitches.cs — switch logic
src/NServiceBus.Core/Hosting/HostingComponent.Settings.cs — GenerateHostId branch
src/NServiceBus.Core/Hosting/HostingComponent.cs — startup warning
src/NServiceBus.Core/Utils/LegacyDeterminsticGuid.cs — legacy implementation (marked PreObsolete, remove in v12)
src/NServiceBus.Core/Utils/DeterministicGuid.cs — current XxHash128-based implementation
In v10, the AppContext switch
NServiceBus.Core.Hosting.UseV2DeterministicGuidmust be explicitly set totrueto opt into the newDeterministicGuid(XxHash128-based). The default remains the legacy MD5-based algorithm. In v11, this should be flipped: XxHash128 becomes the default, and users who need to preserve their existing MD5-based host IDs must explicitly set the switch tofalse.Motivation
HostingComponent.Settings.cs:118).Changes Required
AppContextSwitches.UseV2DeterministicGuiddefaultIn
AppContextSwitches.cs, change the logic so that the switch defaults totrue(use v2) unless explicitly set tofalse:HostingComponent.InitializeThe current warning tells users how to opt into v2. It should be inverted to warn users who are on the legacy path that they should migrate, and that the legacy class will be removed in v12.
Consider renaming
UseV2DeterministicGuidSwitchNameto something likeUseLegacyDeterministicGuidSwitchName(or keeping the old name as a compat alias) so the name reflects the new semantics: setting it totruemeans "use the old MD5 algorithm". Update the documentation strings, environment variable guidance, andUsedLegacyDeterministicGuidSettingsKeyaccordingly.HostingComponent.Settings.GenerateHostIdInvert the branch: the default path uses
DeterministicGuid.Create, and only when the switch explicitly opts into legacy does it useLegacyDeterministicGuid.Create.PreObsoleteonLegacyDeterministicGuidThe annotation already marks it for removal in v12 with
DeterministicGuidas the replacement. No change needed there.Breaking Change
This is a host ID breaking change for endpoints that do not explicitly set the switch. Endpoints that rely on the MD5-based host ID (e.g., for correlating with existing ServicePulse entries) will get a new host ID after upgrading unless they set:
Or via environment variable (.NET 9+):
DOTNET_NServiceBus_Core_Hosting_UseV2DeterministicGuid=falseFollow-up (v12)
Remove
LegacyDeterministicGuidand the AppContext switch entirely.References
src/NServiceBus.Core/AppContextSwitches.cs— switch logicsrc/NServiceBus.Core/Hosting/HostingComponent.Settings.cs—GenerateHostIdbranchsrc/NServiceBus.Core/Hosting/HostingComponent.cs— startup warningsrc/NServiceBus.Core/Utils/LegacyDeterminsticGuid.cs— legacy implementation (markedPreObsolete, remove in v12)src/NServiceBus.Core/Utils/DeterministicGuid.cs— current XxHash128-based implementation