What this thread does
Do first: move Isolate.run into a separate helper whose arguments contain only the computation's sendable input data.
Short answer
As of November 2026, the current Dart API identifies Dart 3.14.1 (send API); Isolate.run is available since 2.19 (API, Marya Belanger's January 24, 2023 announcement). For older SDKs, choose Isolate.spawn plus ports. A closure can transfer more state than its expression mentions. Invalid argument(s): Illegal argument in isolate message can therefore refer to an implicitly captured openFile (run).
Choose / don't choose
Isolate.run: choose for a single computation and returned result; don't create its closure in an object/resource-heavy scope when the captured graph is unclear.- Top-level
Isolate.spawnentry: choose for explicit message boundaries or a longer-lived worker; don't pass a bound service method or a service instance containing unsendable resources.entryPointmay be a closure, so changing API alone is insufficient (spawn).
Not for: Flutter agent analyzer setup; see flutter-dart-agent-plugin.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
Isolate.run computation | Zero-argument callable; use an isolated helper scope taking only required data; result and errors must also be sendable | run annotation: @Since("2.19") | run |
Isolate.spawn entryPoint | Function callable with a single message argument; closures may implicitly send unexpected state | Current Dart API | spawn |
Isolate.spawn message | Send only the required transitive data graph and, when communicating back, a SendPort; not a socket/service owner | Current same-code isolates | spawn, send restrictions |
Isolate.spawn onError / onExit | Provide ports at spawn time when observing errors/exit; attaching listeners afterward can race termination | Current Dart API | spawn |
Same-code isolates can send many ordinary objects; a user-defined data class is not inherently forbidden. The entire reachable graph matters. ReceivePort, native-resource objects and marked unsendable classes are excluded; a SendPort is permitted. Mutable data is generally copied, while the run API says its result is sent through exit without copying (send, run).
Order of operations
1. Inspect the exception's object chain. In filiph's January 8, 2026 report, reading instance fields captures this, which reaches a timer; a top-level computation function alone did not prevent capture at its call site. 2. Extract the needed values through a helper boundary. The example defines encode(o) => Isolate.run(() => jsonEncode(o)) in its own function scope. Renaming a closure or making its body shorter does not bound its capture (run). 3. If explicit worker state/lifecycle is required, use an entryPoint callable with one message argument, create resources inside the worker, and provide onExit and onError when spawning (spawn).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Illegal argument in isolate message | Closure captures openFile | Create a function to call Isolate.run taking all required state as arguments | official open-file example |
object is unsendable | A captured receiver reaches a timer in the reported object graph | Inspect the this edge, pass required values through a helper, and retain the resource-owning controller in the original isolate | filiph report |
The VM overcapture limitation remains documented with jensjoha's May 16, 2019 issue; no fixed-in release is established here.
Missing
- A specific application's sendable graph cannot be inferred from the closure's visible expression; inspect its actual exception chain.
Checked
2026-11-24; current Dart 3.14.1 API, 2.19 introduction annotation and announcement, run/spawn/send references, jensjoha and filiph reports read. No isolate code executed.
Started from a post by @Dart, packaged by the editor. Original post