# Unhandled exception: IsolateSpawnException: Failed to deserialize message: type 'List<dynamic>' is not a subtype of type 'List<int>' in type cast

- **ID:** `flutter/isolate-message-deserialization`
- **Domain:** flutter
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

When sending a message between isolates, the data must be serializable and have exact types; a List containing mixed types or untyped lists caused a type cast failure during deserialization.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Flutter 3.13.0 | active | — | — |
| Flutter 3.22.0 | active | — | — |
| Dart 3.1.0 | active | — | — |

## Workarounds

1. **Explicitly cast the list to the expected type before sending. Example:
  List<int> data = [1, 2, 3];
  await isolate.spawn(workerFunction, data);
If data comes from a dynamic source, use 'List<int>.from(data)' to ensure type safety.** (85% success)
   ```
   Explicitly cast the list to the expected type before sending. Example:
  List<int> data = [1, 2, 3];
  await isolate.spawn(workerFunction, data);
If data comes from a dynamic source, use 'List<int>.from(data)' to ensure type safety.
   ```
2. **Use a typed data class that implements 'toMap' and 'fromMap' for serialization. Example:
  class MyMessage {
    final List<int> values;
    MyMessage(this.values);
    Map<String, dynamic> toMap() => {'values': values};
    factory MyMessage.fromMap(Map<String, dynamic> map) => MyMessage(List<int>.from(map['values']));
  }
Then send the map and deserialize in the isolate.** (80% success)
   ```
   Use a typed data class that implements 'toMap' and 'fromMap' for serialization. Example:
  class MyMessage {
    final List<int> values;
    MyMessage(this.values);
    Map<String, dynamic> toMap() => {'values': values};
    factory MyMessage.fromMap(Map<String, dynamic> map) => MyMessage(List<int>.from(map['values']));
  }
Then send the map and deserialize in the isolate.
   ```
3. **Ensure the list is created with a concrete type parameter, e.g., 'List<int>.empty(growable: true)' instead of '[]' which defaults to List<dynamic>.** (75% success)
   ```
   Ensure the list is created with a concrete type parameter, e.g., 'List<int>.empty(growable: true)' instead of '[]' which defaults to List<dynamic>.
   ```

## Dead Ends

- **Use 'List<dynamic>' as the type for the message variable** — The isolate communication protocol requires concrete types; <dynamic> is not concrete and causes the same error when the receiver expects a specific type. (70% fail)
- **Wrap the message in a Map with string keys to bypass type checking** — Maps also require concrete type parameters; a Map<String, dynamic> still fails if the receiver expects Map<String, int>. (60% fail)
- **Set '--no-verify-types' flag in the Dart VM** — This flag does not exist; type verification is inherent to the isolate protocol and cannot be disabled. (90% fail)
