Invalid argument(s): Illegal argument in isolate message: (object is aReceivePort)
I actually opened a ticket for a similar issue about a month ago:
https://github.com/dart-lang/sdk/issues/47981
Turns out there was already a ticket for it here:
https://github.com/dart-lang/sdk/issues/36983
I believe what is happening here is that because _processWorkItemsInBackground
is not a top level function, it is closing over all of the variables that are in scope, that would include this declaration late final ReceivePort _receivePort;
. And so when you spawn the isolate with _processWorkItemsInBackground
it is implicitly attempting to send to the isolate everything in scope, but ReceivePort
s are not allowed to be sent to an isolate, thus causing the error.