Tech Tip: Avoid Storing Unsupported Types in Shared Objects (error -10721)
PRODUCT: 4D | VERSION: 21 | PLATFORM: Mac & Win
Published On: December 9, 2025
When assigning values to a shared object or a shared collection. Attempting to store a non-shareable type such as a 4D.FileHandle, 4D.File will raise the following runtime error: error -10721 Not supported value type in a shared object or a shared collection.
For example, the following code fails because FileHandle cannot be stored inside shared memory:
Solution
Instead of storing the FileHandle in the shared object, store something serializable, like the file path, and handle opening/writing/closing outside the shared block.
For example, the following code fails because FileHandle cannot be stored inside shared memory:
| // --- This will FAIL with error -10721 --- var $so : Object $so:=New shared object() var $file : 4D.File var $fh : 4D.FileHandle $file:=Folder(Database folder).file("test_shared_error.log") $fh:=$file.open({mode: "append"; charset: "UTF-8"}) Use ($so) $so.handle:=$fh End use |
Solution
Instead of storing the FileHandle in the shared object, store something serializable, like the file path, and handle opening/writing/closing outside the shared block.
| var $so : Object $so:=New shared object() var $file : 4D.File var $fh : 4D.FileHandle $file:=Folder(Database folder).file("test_shared_ok.log") $fh:=$file.open({mode: "append"; charset: "UTF-8"}) Use ($so) $so.path:=$file.platformPath End use $fh.writeLine("This line is legal because the handle is not stored in shared memory.") $fh:=Null |