StrictGuid 1.0.0

dotnet add package StrictGuid --version 1.0.0
                    
NuGet\Install-Package StrictGuid -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StrictGuid" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StrictGuid" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="StrictGuid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StrictGuid --version 1.0.0
                    
#r "nuget: StrictGuid, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StrictGuid@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StrictGuid&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=StrictGuid&version=1.0.0
                    
Install as a Cake Tool

StrictGuid (UUID v8)

StrictGuid is a high-performance .NET library for working with typed identifiers based on the RFC 9562 standard (UUID v8). It allows you to embed the entity type directly into the GUID, ensuring strict typing at the domain model level without sacrificing performance.

Key Features

  • 🚀 Extreme Speed: 55x faster than standard Guid.NewGuid() in Fast mode.
  • 💎 Zero-Allocation: Zero heap allocations (0 bytes).
  • 🛡️ Type-Safe: Binds IDs to your enum : byte (supports up to 256 types).
  • 🔒 Entropy Choice: Fast (Random), Secure (Crypto), and Sequential (DB-friendly).
  • 📏 UUID v8 Compliance: Fully compliant with RFC 9562.
  • 🛡️ Reliability: Strict protection against regular UUID v4 and "garbage" GUIDs.

Solution Structure

  • src/StrictGuid.Library: The core library (Extension methods, generator).
  • tests/StrictGuid.Tests: Unit tests (xUnit).
  • benchmarks/StrictGuid.Benchmarks: Performance tests (BenchmarkDotNet).
  • samples/StrictGuid.Demo: Usage example.

Benchmark Results

Performance comparison on .NET 10.0.202 (Apple M1):

Method Mean Ratio Allocated
StandardNewGuid 255.00 ns 1.00 -
StrictGuidFast 4.65 ns 0.02 -
StrictGuidSequential 27.81 ns 0.11 -
StrictGuidSecure 256.86 ns 1.01 -
ExtractType 6.73 ns 0.03 -

The Sequential mode provides an excellent balance: it is 9x faster than a standard GUID and guarantees correct sorting (prevents index fragmentation) in the DB. The Fast mode outperforms the regular GUID generator by 55 times.

Installation

You can install the package from NuGet via the .NET CLI:

dotnet add package StrictGuid

Or via the Package Manager Console in Visual Studio:

Install-Package StrictGuid

Usage

1. Defining Types

Your enums must be based on the byte type. You can define both domain entities and service types (e.g., logging, webhooks):

public enum EntityType : byte
{
    // Service types
    Log = 0,
    WebHook = 1,
    Request = 2,

    // Domain entities
    User = 3,
    Order = 4,
    Invoice = 5,
    // ... supports up to 256 types
}

2. Generating IDs

using StrictGuid.Library;

// Sequential ID (UUID v7 style) — recommended for DBs
Guid orderId = EntityType.Order.NewStrictGuid(StrictGuidEntropy.Sequential);

// Ultra-fast random ID (for logs or transactions)
Guid logId = EntityType.Log.NewStrictGuid(StrictGuidEntropy.Fast);

// Cryptographically secure ID (tokens)
Guid secretId = EntityType.User.NewStrictGuid(StrictGuidEntropy.Secure);

3. Extraction and Validation

// Extracting type
EntityType type = id.GetEntityType<EntityType>();

// Fast validation (throws StrictGuidException on mismatch)
id.ValidateEntityType(EntityType.Order);

// Safe logical check
if (id.IsEntityType(EntityType.User))
{
    // ...
}

Security and Entropy Choice

Mode Source Order When to use
Fast Random.Shared Random Regular IDs, high speed, logs.
Secure Crypto Random Secret tokens, passwords, sessions.
Sequential Time + Random Sequential Primary Keys (PK) in DB, sortable lists.

Type Isolation and Protection against UUID v4

The library reliably isolates entity types. The validation or type extraction method is guaranteed to detect mismatches.

If a standard UUID v4 is passed to your system (e.g., generated by a normal Guid.NewGuid()), the library will not confuse it with an entity (even an entity with code 0, like Log). The algorithm strictly checks the version bits (UUID v8 requires the value 0x80 in the upper bits of the 7th byte). If a v4 or garbage GUID is passed:

  • IsEntityType will safely return false.
  • GetEntityType or ValidateEntityType will throw a StrictGuidException.

System Requirements

  • .NET 8.0+, .NET 6.0, or .NET Standard 2.0
  • Support for System.Runtime.CompilerServices.Unsafe (included automatically in newer .NET, added as a NuGet package for .NET Standard 2.0)

Optimizations

  • AggressiveInlining & AggressiveOptimization to eliminate call overhead.
  • Unsafe.As for Zero-allocation type conversions.
  • Span<byte> & stackalloc for stack-based memory operations.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 66 4/20/2026