{
  "id": "unity/il2cpp-array-type-mismatch",
  "signature": "IL2CPP error: System.InvalidCastException: Specified cast is not valid. Array type 'System.Int32[]' cannot be assigned to array of type 'System.Single[]'",
  "signature_zh": "IL2CPP错误：System.InvalidCastException：指定的强制转换无效。数组类型'System.Int32[]'无法分配给类型'System.Single[]'的数组",
  "regex": "IL2CPP error: System\\.InvalidCastException: Specified cast is not valid\\. Array type 'System\\.Int32\\[\\]' cannot be assigned to array of type 'System\\.Single\\[\\]'",
  "domain": "unity",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "IL2CPP code stripping or type conversion issue where an int array is incorrectly cast to a float array, often due to unsafe code or marshaling.",
  "root_cause_type": "generic",
  "root_cause_zh": "IL2CPP代码剥离或类型转换问题，其中整数数组被错误地转换为浮点数组，通常是由于不安全的代码或封送处理。",
  "versions": [
    {
      "version": "Unity 2022.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2023.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "IL2CPP 1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disabling code stripping entirely may fix the cast but increases build size and hides the real issue; the cast is still incorrect.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding explicit casts in C# code does not help because the error occurs during IL2CPP conversion of array types, not at runtime.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Avoid direct array type conversion; use Array.ConvertAll() or LINQ Select() to create a new array: float[] floatArray = intArray.Select(i => (float)i).ToArray();",
      "success_rate": 0.85,
      "how": "Avoid direct array type conversion; use Array.ConvertAll() or LINQ Select() to create a new array: float[] floatArray = intArray.Select(i => (float)i).ToArray();",
      "condition": "",
      "sources": []
    },
    {
      "action": "Mark the method with [Il2CppSetOption(Option.NullChecks, false)] to suppress the IL2CPP check, but only if the cast is safe (not recommended for production).",
      "success_rate": 0.7,
      "how": "Mark the method with [Il2CppSetOption(Option.NullChecks, false)] to suppress the IL2CPP check, but only if the cast is safe (not recommended for production).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "避免直接数组类型转换；使用Array.ConvertAll()或LINQ Select()创建新数组：float[] floatArray = intArray.Select(i => (float)i).ToArray();",
    "使用[Il2CppSetOption(Option.NullChecks, false)]标记方法以抑制IL2CPP检查，但仅在转换安全时使用（不推荐用于生产）。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/Manual/IL2CPP-ErrorCodes.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}