FilePut does not prepend the two length bytes when writing a string to a binary file from C#. FilePutObject throws exceptions on classes/structs

核能气质少年 提交于 2019-12-06 10:04:21

FilePutObject seems to be a lot more verbose and write out more metadata than is needed, primarily for variants.
Have you tried just:

FileSystem.FilePut(file, patch);

This uses the "ValueType" overload.

You can write the length out explicitly before the string:

FileSystem.FilePut(file, patch.stringTest.Lenght.ToInt16);
FileSystem.FilePut(file, patch.stringTest, StringIsFixedLength: false);

Change to:

FileSystem.FilePut(file, patch.stringTest, StringIsFixedLength: false);

The system isn't writing the length prefix because you're telling it the string is fixed length.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!