FileMappingMBS: Error when copying JSONItem

I am testing FileMappingMBS for desktop/console helper communication. Seems to be pretty fast, but I run into a problem when using SetSharedMemoryValue for the transmission of a JSONItem string. I copied the methods from the MBS examples mostly, defining UTF8 encoding.

The received data looks totally fine when logging it, but trying to make a JSON out of it will always result in a

Exception 0 parse error: trailing garbage

I trimmed the received string, and I tried to extend the memory block to make sure a zero byte is included. But to no avail. Page size is 4096 only; I do not transmit large data currently.
Any hints what I might be doing wrong?

Did you inspect string in debugger?
Maybe you may need to cut it at the first Chr(0)?

Debugging is not that easy as I am starting the compiled helper from within the desktop app.
But thanks for the hint. Think I’ll try to see if string lengths are same before and after.

Whenever you get a JSON exception in parsing a file, it may be good to write the string to parse into a temp file to inspect.

Uh – I found the error, but I have no idea what might be the cause.
Before sending, the JSON string has a length of 571 Bytes. After receive, it is reported as 4096 bytes, with the rest of the page being 0 bytes.
Isn’t the size transmitted? Should I add a length property to the SharedMemory to cut strings back to their size?

for JSON you could just cut it after first Chr(0).

Size may be rounded to next block size.

1 Like

Thank you. Fixed it by using Trim(Chr(0)).
I thought there would be more issues, but that was my console command handling. Works now!

Thanks. I’ll put in a note in the documentation.