Repro program:
import 'dart:async';
import 'dart:isolate';
void main() async {
var i = 0;
void childIsolateFn(SendPort sendPort) {
sendPort.send(i);
}
var receivePort = ReceivePort();
var isolate = await Isolate.spawn(childIsolateFn, receivePort.sendPort);
}
This fails with the error Invalid argument(s): Illegal argument in isolate message: (object is aReceivePort).
It seems valid that you can't refer to local variables in this case - but the error is very misleading and doesn't help you to diagnose the actual problem.