{
  "id": "dotnet/aspnetcore-options-validation-failure",
  "signature": "Microsoft.Extensions.Options.OptionsValidationException: A configuration validation error occurred. DataAnnotation validation failed for 'MyOptions' members: 'ApiKey' is required.",
  "signature_zh": "Microsoft.Extensions.Options.OptionsValidationException: 发生配置验证错误。'MyOptions'成员的数据注释验证失败：'ApiKey'是必需的。",
  "regex": "OptionsValidationException.*DataAnnotation validation failed",
  "domain": "dotnet",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "ASP.NET Core's options validation using DataAnnotations (e.g., [Required]) is triggered at startup via ValidateOnStart(), but the required configuration key is missing or empty in appsettings.json or environment variables.",
  "root_cause_type": "generic",
  "root_cause_zh": "ASP.NET Core使用数据注释（例如[Required]）的选项验证在启动时通过ValidateOnStart()触发，但appsettings.json或环境变量中缺少或为空必需的配置键。",
  "versions": [
    {
      "version": ".NET 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ASP.NET Core 6.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding a default value in the options class constructor to avoid null",
      "why_fails": "Validation is based on DataAnnotations attributes, not null checks; a default value does not satisfy [Required] if the config key is missing.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing ValidateOnStart() to defer validation until first use",
      "why_fails": "The error moves to runtime, causing unexpected failures later; the root issue (missing config) remains.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add the missing configuration key to appsettings.json or environment variables with the correct path matching the options class hierarchy.",
      "success_rate": 0.95,
      "how": "Add the missing configuration key to appsettings.json or environment variables with the correct path matching the options class hierarchy.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the value is optional, remove the [Required] attribute from the property and handle null checks in code.",
      "success_rate": 0.8,
      "how": "If the value is optional, remove the [Required] attribute from the property and handle null checks in code.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Add the missing configuration key to appsettings.json or environment variables with the correct path matching the options class hierarchy.",
    "If the value is optional, remove the [Required] attribute from the property and handle null checks in code."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-8.0#options-validation",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-04-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}