3

I am trying to read a binary file in which i have been appending data using a BinaryWriter object. I keep getting this error:

"The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'."

My file has characters like | which i suspect are the problem but I don't know how to solve it.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
Kevin Ledama
  • 131
  • 2
  • 7

1 Answers1

4

The most probable reason is that your file contains some binary data, that does not represent valid UTF-8 codepoint, at the place from which you are trying to read UTF-8 character.

This can happen if your read algorithm lose "synchronization" with your write algorithm and tries to read character from the wrong place, where something else (not a character) was written.

mas.morozov
  • 2,666
  • 1
  • 22
  • 22