When working with System.Text.Json in .NET projects with Native AOT compilation, use source generation for optimal performance and compatibility.
Define a partial class that inherits from JsonSerializerContext and use attributes to configure serialization:
using System.Text.Json.Serialization;
[JsonSourceGenerationOptions(
WriteIndented = true,
PropertyNamingPolicy = JsonKnownNamingPolicy.KebabCaseLower,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping)]
[JsonSerializable(typeof(JsonNode))]
[JsonSerializable(typeof(JsonObject))]
[JsonSerializable(typeof(JsonArray))]
[JsonSerializable(typeof(CveRecords))]
public partial class CveJsonSerializerContext : JsonSerializerContext
{
}// Serialize
var jsonString = JsonSerializer.Serialize(jsonDoc, CveJsonSerializerContext.Default.JsonNode);
// Deserialize
var cveRecords = JsonSerializer.Deserialize(jsonString, CveJsonSerializerContext.Default.CveRecords);- ✅ Full NAOT compatibility
- ✅ No reflection at runtime
- ✅ Better performance
- ✅ Smaller binary size
- ✅ No runtime warnings
See /Users/rich/git/distroessed/src/DotnetRelease/DataModel/Other/CveInfoSerializationContext.cs for the canonical example used in the .NET release tooling.
CVE JSON files must follow this exact property order per the C# schema:
idtitleseveritycvssdescription(optional)mitigation(optional)product(optional)platforms(optional)references
Use the fix-cve-order-naot.cs script to automatically reorder properties in all CVE JSON files using NAOT-compatible source generation.
# Check current status
git status
# View recent commits
git log --oneline -5
# View changes in a specific commit
git show <commit-hash>- CVE JSON files:
/release-notes/history/YYYY/MM/cve.json - CVE Markdown files:
/release-notes/{6.0,7.0,8.0,9.0}/cve.md - Schema definition:
/Users/rich/git/distroessed/src/DotnetRelease/DataModel/Other/CveRecords.cs - Serialization context:
/Users/rich/git/distroessed/src/DotnetRelease/DataModel/Other/CveInfoSerializationContext.cs
We developed a comprehensive C# framework for testing how effectively LLMs can navigate and use structured documentation. The framework was originally designed for .NET release documentation but built to be reusable for any documentation scheme.
Created llm-doc-tester - a complete C# project at /Users/rich/git/llm-doc-tester/ containing:
src/
├── Program.cs # Main CLI interface with --all-models, --output options
├── DotNetReleaseDocTester.csproj # .NET 10.0 project file
├── Models/
│ ├── TestModels.cs # TestCase, TestCriteria, TestResult, TestResults, ScoreResult
│ └── ChatModels.cs # ChatMessage, ChatResponse for OpenRouter API
└── Services/
├── OpenRouterClient.cs # HTTP client for OpenRouter API integration
├── TestCaseLoader.cs # 15 comprehensive test cases across 5 categories
├── TestFramework.cs # Main test execution engine with system prompt
├── ResponseScorer.cs # 5-criteria scoring: Accuracy, Completeness, HAL Usage, Source Citation, Format
└── ReportGenerator.cs # Detailed markdown report generation
- Multi-Model Testing: OpenRouter API integration (Claude, GPT-4, Gemini)
- 15 Test Cases across 5 categories:
- Basic Info (3 tests): LTS versions, EOL dates, supported versions
- CVE Analysis (3 tests): Date-based CVE retrieval, version-specific analysis, cross-version comparison
- HAL Navigation (3 tests): Patch release navigation, platform-specific downloads, version indexes
- Cross-Reference (3 tests): CVE impact analysis, commit history, version relationships
- Error Handling (3 tests): Non-existent versions, future dates, unsupported platforms
- 5-Criteria Scoring System: Each response scored 0-1.0 on accuracy, completeness, HAL usage, source citation, format
- System Prompt: Directs LLMs to use structured JSON data from GitHub raw URLs with HAL navigation
- Environment:
OPENROUTER_API_KEYrequired - Usage:
dotnet run [--all-models] [--output file.md] - Target Framework: .NET 10.0
✅ Complete framework implemented
✅ Moved to separate repository /Users/rich/git/llm-doc-tester/
✅ Updated to .NET 10.0
⏳ Next Step: Validate build in new directory (requires restarting Claude Code in /Users/rich/git/llm-doc-tester/)
- Reusable: Easy to adapt for different documentation schemes
- Comprehensive: Tests navigation, accuracy, source citation, error handling
- Measurable: Quantitative scoring with detailed reports
- API-First: Uses production LLM APIs rather than web interfaces
To adapt for new documentation:
- Update test cases in
TestCaseLoader.cs - Modify system prompt in
TestFramework.cs - Adjust scoring criteria in
ResponseScorer.cs - Update expected keywords/URLs for new domain
- Uses OpenAI-compatible API pattern
- HAL+JSON navigation testing built-in
- Async/await throughout for performance
- Comprehensive error handling and rate limiting
- Markdown report generation with recommendations
llms.txt: AI assistant discovery file with .NET release metadata entry pointsCVE_PROJECT_SUMMARY.md: Background on CVE JSON property ordering work- Previous CVE ordering scripts:
fix-cve-order-final.cs