# IL2CPP error: System.InvalidCastException: Specified cast is not valid. Array type 'System.Int32[]' cannot be assigned to array of type 'System.Single[]'

- **ID:** `unity/il2cpp-array-type-mismatch`
- **Domain:** unity
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Unity 2022.3 | active | — | — |
| Unity 2023.2 | active | — | — |
| IL2CPP 1.0 | active | — | — |

## Workarounds

1. **Avoid direct array type conversion; use Array.ConvertAll() or LINQ Select() to create a new array: float[] floatArray = intArray.Select(i => (float)i).ToArray();** (85% success)
   ```
   Avoid direct array type conversion; use Array.ConvertAll() or LINQ Select() to create a new array: float[] floatArray = intArray.Select(i => (float)i).ToArray();
   ```
2. **Mark the method with [Il2CppSetOption(Option.NullChecks, false)] to suppress the IL2CPP check, but only if the cast is safe (not recommended for production).** (70% success)
   ```
   Mark the method with [Il2CppSetOption(Option.NullChecks, false)] to suppress the IL2CPP check, but only if the cast is safe (not recommended for production).
   ```

## Dead Ends

- **** — Disabling code stripping entirely may fix the cast but increases build size and hides the real issue; the cast is still incorrect. (50% fail)
- **** — Adding explicit casts in C# code does not help because the error occurs during IL2CPP conversion of array types, not at runtime. (75% fail)
