{
  "id": "dotnet/illegal-char-in-path",
  "signature": "System.ArgumentException: Illegal characters in path.",
  "signature_zh": "System.ArgumentException: 路径中存在非法字符。",
  "regex": "Illegal characters in path",
  "domain": "dotnet",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A file path contains characters not allowed by the operating system, such as colons, asterisks, or angle brackets, often due to user input or malformed configuration.",
  "root_cause_type": "generic",
  "root_cause_zh": "文件路径包含操作系统不允许的字符，例如冒号、星号或尖括号，通常是由于用户输入或配置格式错误。",
  "versions": [
    {
      "version": "net6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "net7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "net8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "net9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Hardcoding the path with a different separator (e.g., using '/' instead of '\\')",
      "why_fails": "The issue is not the separator but illegal characters like ':', '?', '*' which are invalid on Windows regardless of separator.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using Path.GetInvalidPathChars() to remove characters but only checking for a subset",
      "why_fails": "GetInvalidPathChars() does not include all illegal characters (e.g., ':' is valid for drive letters but not in middle of path), leading to incomplete validation.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Truncating the path to a fixed length",
      "why_fails": "Truncation does not remove illegal characters; it may cut off valid parts and still leave invalid chars.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Sanitize the path using Path.GetInvalidFileNameChars() and Path.GetInvalidPathChars() to replace or remove illegal characters. Example: 'string safePath = string.Concat(path.Where(c => !Path.GetInvalidPathChars().Contains(c) && !Path.GetInvalidFileNameChars().Contains(c)));'",
      "success_rate": 0.9,
      "how": "Sanitize the path using Path.GetInvalidFileNameChars() and Path.GetInvalidPathChars() to replace or remove illegal characters. Example: 'string safePath = string.Concat(path.Where(c => !Path.GetInvalidPathChars().Contains(c) && !Path.GetInvalidFileNameChars().Contains(c)));'",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Path.Combine() to build paths safely instead of string concatenation. For user input, validate with a regex like '^[a-zA-Z0-9_\\\\-./\\\\s]+$' and reject invalid input early.",
      "success_rate": 0.85,
      "how": "Use Path.Combine() to build paths safely instead of string concatenation. For user input, validate with a regex like '^[a-zA-Z0-9_\\\\-./\\\\s]+$' and reject invalid input early.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrap file path operations in try-catch for ArgumentException and log the path for debugging. Then, implement a fallback like using a GUID-based file name: 'string safeFileName = Guid.NewGuid().ToString() + Path.GetExtension(originalPath);'",
      "success_rate": 0.8,
      "how": "Wrap file path operations in try-catch for ArgumentException and log the path for debugging. Then, implement a fallback like using a GUID-based file name: 'string safeFileName = Guid.NewGuid().ToString() + Path.GetExtension(originalPath);'",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Sanitize the path using Path.GetInvalidFileNameChars() and Path.GetInvalidPathChars() to replace or remove illegal characters. Example: 'string safePath = string.Concat(path.Where(c => !Path.GetInvalidPathChars().Contains(c) && !Path.GetInvalidFileNameChars().Contains(c)));'",
    "Use Path.Combine() to build paths safely instead of string concatenation. For user input, validate with a regex like '^[a-zA-Z0-9_\\\\-./\\\\s]+$' and reject invalid input early.",
    "Wrap file path operations in try-catch for ArgumentException and log the path for debugging. Then, implement a fallback like using a GUID-based file name: 'string safeFileName = Guid.NewGuid().ToString() + Path.GetExtension(originalPath);'"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/dotnet/api/system.io.pathtoo longexception?view=net-8.0",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-03-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}