一个 .NET 5 项目,运行下面的代码:
using (var ms = new MemoryStream(File.ReadAllBytes(FileStorePathTable)))
{
using (var reader = new BinaryReader(ms))
{
for (int i = 0; i < _itemNumber; i++)
{
if (reader.PeekChar() == -1)
break;
//...
}
}
}
出现下面的错误:
The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'
请问如何解决?
stackoverflow 上的相关问题:C# BinaryReader.ReadChar throws “System.ArgumentException: The output char buffer is too small” when reading NetworkStream
– dudu 4年前