Skip to main content
This guide shows you how to integrate Avalex license validation into a C# application targeting .NET Core, WPF, or WinForms. You will use the built-in HttpClient for the HTTP request, System.Security.Cryptography.SHA256 for HWID hashing, and the System.Text.Json source-generation-friendly attributes for clean serialization — no third-party dependencies required.

Full Example

The class below is self-contained and ready to add to any .NET project. Update ApiUrl and ProductId to match your deployment before shipping.

Code Walkthrough

HWID generation (GetHwid) GetHwid combines Environment.MachineName, Environment.UserName, and Environment.ProcessorCount into a single string and computes its SHA-256 hash using the built-in SHA256.Create() factory. The raw hash bytes are converted to an uppercase hex string and truncated to 32 characters. You can strengthen this by adding more stable identifiers (e.g., the motherboard serial number via WMI), but the combination above is sufficient for most desktop deployments. Typed request and response models ValidateRequest and ValidateResponse use [JsonPropertyName] attributes to map C# PascalCase properties to the camelCase JSON field names expected by the Avalex API. This approach is compatible with System.Text.Json’s source generator and avoids any dependency on Newtonsoft.Json. Async usage (ValidateAsync) ValidateAsync is a Task<bool> method, making it straightforward to await from any modern async entry point. The PostAsJsonAsync extension method serializes the request object and sets the Content-Type header automatically. If the HTTP response is successful, ReadFromJsonAsync<ValidateResponse> deserializes the body. Any exception — network failure, DNS error, timeout — is caught and logged, and the method returns false so your application defaults to a locked state on unexpected errors.
Replace ApiUrl with your production HTTPS endpoint before distributing your application. The http://localhost:8080 address is for local development only.
For WPF or WinForms applications, call ValidateAsync from your startup window’s Loaded event handler (or Form.Load) before making the main UI visible. This ensures users never see the application interface before their license has been confirmed.