ErrorCodes.Net.Analyzers
0.2.2
dotnet add package ErrorCodes.Net.Analyzers --version 0.2.2
NuGet\Install-Package ErrorCodes.Net.Analyzers -Version 0.2.2
<PackageReference Include="ErrorCodes.Net.Analyzers" Version="0.2.2" />
<PackageVersion Include="ErrorCodes.Net.Analyzers" Version="0.2.2" />
<PackageReference Include="ErrorCodes.Net.Analyzers" />
paket add ErrorCodes.Net.Analyzers --version 0.2.2
#r "nuget: ErrorCodes.Net.Analyzers, 0.2.2"
#:package ErrorCodes.Net.Analyzers@0.2.2
#addin nuget:?package=ErrorCodes.Net.Analyzers&version=0.2.2
#tool nuget:?package=ErrorCodes.Net.Analyzers&version=0.2.2
๐ ๏ธ ErrorCodes.Net
ErrorCodes.Net is a .NET library and Roslyn analyzer that helps you define and manage structured, traceable error codes across your applications.
It enforces a consistent format:
0xPPMMTTTT
Where:
PP= Product ID (e.g.,00for Service A,01for Service B)MM= Project ID (e.g.,06)TT= Error Type IDTT= Error Code
This structure ensures that each error code is unique, traceable, and easy to interpret.
๐ Features
- โ Enforces consistent error code formatting via Roslyn analyzers
- โ YAML-based configuration for defining error codes
- โ Supports multiple error types per project
- โ Generates C# code for defined error codes
- โ Integrates seamlessly with your build process
โฌ๏ธ Installation
Install the analyzer via NuGet:
dotnet add package ErrorCodes.Net.Analyzers
In your .csproj file, ensure the package is referenced with PrivateAssets="all" to prevent it from being exposed to consumers:
<PackageReference Include="ErrorCodes.Net.Analyzers" PrivateAssets="all" />
โ๏ธ Configuration
Create an ErrorCodes.yaml or ErrorCodes.yml file in your project root with the following structure:
projectId: 6
namespace: ErrorCodes.Net.Generated
errorTypes:
- name: TestErrors
errors:
- code: 1
name: InvalidInput
- code: 2
name: NotFound
This configuration defines the project ID, the namespace for the generated code, and a list of error types with their corresponding error codes and messages.
๐งช Example Usage
Once configured, the analyzer will generate a static class with your error codes.
Make sure to include the YAML file in your .csproj so the analyzer can find it:
<ItemGroup>
<AdditionalFiles Include="ErrorCodes.yaml" />
</ItemGroup>
Then you can use the generated error codes like this:
using ErrorCodes.Net.Generated;
public class Example
{
public void DoSomething()
{
var errorCode = ErrorCodeLookup.TestErrors.InvalidInput;
Console.WriteLine(errorCode); // Outputs: 0x06010001
}
}
See a full sample project here.
๐งฐ Advanced Usage
You can define multiple error types within the same project:
projectId: 6
namespace: ErrorCodes.Net.Generated
errorTypes:
- name: ValidationErrors
errors:
- code: 1
name: MissingField
- name: DatabaseErrors
errors:
- code: 1
name: ConnectionFailed
This will generate separate classes for each error type, such as ValidationErrors and DatabaseErrors, each containing their respective error codes.
๐ฆ NuGet Package
The analyzer is available on NuGet:
ErrorCodes.Net.Analyzers on NuGet
๐ค Contributing
Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request.
๐ License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
This package has 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 |
|---|---|---|
| 0.2.2 | 118 | 6/18/2026 |
| 0.2.2-preview.3 | 65 | 6/18/2026 |
| 0.2.2-preview.2 | 211 | 4/14/2025 |
| 0.2.2-preview.1 | 203 | 4/14/2025 |
| 0.2.1 | 241 | 5/7/2024 |
| 0.2.0 | 197 | 4/30/2024 |
| 0.1.1-preview.8 | 114 | 4/30/2024 |
| 0.1.1-preview.7 | 118 | 4/26/2024 |
| 0.1.1-preview.6 | 116 | 4/25/2024 |
| 0.1.1-preview.5 | 117 | 4/23/2024 |
| 0.1.1-preview.4 | 107 | 4/23/2024 |
| 0.1.1-preview.3 | 122 | 4/22/2024 |