ConfigurationOptionsValidator 1.0.7

dotnet add package ConfigurationOptionsValidator --version 1.0.7
                    
NuGet\Install-Package ConfigurationOptionsValidator -Version 1.0.7
                    
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="ConfigurationOptionsValidator" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConfigurationOptionsValidator" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="ConfigurationOptionsValidator" />
                    
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 ConfigurationOptionsValidator --version 1.0.7
                    
#r "nuget: ConfigurationOptionsValidator, 1.0.7"
                    
#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 ConfigurationOptionsValidator@1.0.7
                    
#: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=ConfigurationOptionsValidator&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=ConfigurationOptionsValidator&version=1.0.7
                    
Install as a Cake Tool

ConfigurationOptionsValidator

Version 1.0.7

ConfigurationOptionsValidator is a lightweight, powerful, and fully automated configuration validation library for .NET applications.
It ensures that every configuration class in your application is:

✔ Registered
✔ Validated
✔ Checked for missing or invalid values
✔ Logged safely through Serilog
✔ Handled correctly depending on workload (Blazor, API, Console)

ConfigurationOptionsValidator works seamlessly with the Options Pattern, which is a recommended approach for managing configuration in .NET. The Options pattern removes magic strings from your code, making it more readable and flexible. While it’s a great practice to use, even if you’re not using the Options pattern, this library can still help by validating your appsettings values and checking for any missing or incorrect properties.


This library prevents your applications from starting with invalid appsettings.json data, improving reliability, security, and developer experience.

🧩 Framework Support

ConfigurationOptionsValidator supports the following .NET versions via multi-targeting:

  • .NET 8 (LTS)
  • .NET 9
  • .NET 10 (LTS)

The package automatically selects the most appropriate target framework at build time, ensuring maximum compatibility without requiring any changes from consumers.

🚀 What’s New in v1.0.7

  • ✅ Full automation across Blazor, API, and Console workloads
  • Multi-targeting support for .NET 8, .NET 9, and .NET 10
  • ✅ Improved startup validation consistency across application types Version 1.0.7 introduces full automation across all workloads:

Blazor

builder.AddConfigurationValidation();  
app.ValidateBlazorConfigurationOnStartup();

API

builder.AddConfigurationValidation();
builder.ValidateApiConfigurationOnStartup();

Console Applications

builder.AddConfigurationValidation();
host.ValidateConsoleConfigurationOnStartup();

Mandatory Requirement

Every configuration class must implement IValidatedOptions Any class you want automatically validated must implement the marker interface#:

public class SMTPOptions : IValidatedOptions
{
    public string Host { get; set; }
    public int Port { get; set; }
}


Installation

Install the package via NuGet:

dotnet add package ConfigurationOptionsValidator --version 1.0.6


Setup

1. Blazor

In your Program.cs:

var builder = WebApplication.CreateBuilder(args);

// Register validators + discover option types
builder.AddConfigurationValidation();

var app = builder.Build();

// Run validation + show HTML error page if needed
app.ValidateBlazorConfigurationOnStartup();

app.Run();

If a configuration is missing, the user is safely redirected to:

/config-error

The page is automatically generated with your Serilog settings.


2. Web API

In your Program.cs:

var builder = WebApplication.CreateBuilder(args);

// Auto-register validators and discover config types
builder.AddConfigurationValidation();

// Validate API configuration (fail-fast)
builder.ValidateApiConfigurationOnStartup();

var app = builder.Build();


2. Console Application

In your Program.cs:

internal class Program
{
    private static async Task Main(string[] args)
    {
        // Create builder (loads config automatically)
        var builder = Host.CreateApplicationBuilder(args);

        // Auto-register validators + options
        builder.AddConfigurationValidation();

        // Build host
        var host = builder.Build();

        // Validate before running the app
        host.ValidateConsoleConfigurationOnStartup();

        // Run console app logic
        var app = ActivatorUtilities.CreateInstance<ApplicationService>(host.Services);
        await app.RunAsync();
    }
}



Error Page Security for Web Apps

For enhanced security, configure error handling to restrict access to error pages in production environments. You can add the following settings to your appsettings.json to prevent exposing errors to end users:

"ConfigurationErrorPageSettings": {
  "ForbiddenMessage": "Access denied. This page is only visible on the server.",
  "SupportContact": {
    "Email": "support@company.com",
    "Phone": "+44 7890 123456",
    "Website": "https://support.company.com"
  }
}

This prevents leaking sensitive configuration details to the public.


Serilog Logging

If logPath is not set, logs are written to: In your C:\TaskLogs:

You can override the path by setting:

builder.ValidateApiConfigurationOnStartup(logPath: "C:/mylogs");


This prevents leaking sensitive configuration details to the public.


Why Use ConfigurationOptionsValidator?

✔ No more guessing which config values are missing ✔ No more runtime crashes due to bad settings ✔ Works with Blazor, API, Console (automatically) ✔ Instant validation on startup ✔ Secure error handling ✔ Cleaner, more maintainable configuration code


License

This project is licensed under the MIT License. See the LICENSE file for details.

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 is compatible.  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.

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.7 148 12/29/2025
1.0.6 240 11/24/2025
1.0.5 445 11/19/2025
1.0.4 272 4/10/2025
1.0.3 278 2/12/2025
1.0.2 272 2/11/2025 1.0.2 is deprecated.
1.0.1 255 2/11/2025 1.0.1 is deprecated.
1.0.0 246 2/11/2025 1.0.0 is deprecated because it has critical bugs.