バイナリファイル読み込みで”変換バッファのオーバーフロー”について


やおきな  2005-02-24 06:12:52  No: 119873

VB.NETのBinaryReaderで読み込みを行うと、8,145,157Byte目で「変換バッファのオーバーフローです」のエラーがでます。
それよりも小さいファイルですと発生しません。

何か環境設定でも必要なのでしょうか。
よろしくお願いいたします。

        Dim fsi As System.IO.FileStream = New System.IO.FileStream(TextBoxPath.Text, IO.FileMode.Open)
        Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fsi)
         Dim aBuf As Byte

        lCntCopy = 0
        Do While br.PeekChar() <> -1
            aBuf = br.ReadByte
            bw.Write(aBuf)
            lCntCopy = lCntCopy + 1
        Loop


いな  2005-02-24 09:37:19  No: 119874

過去ログで
http://madia.world.coocan.jp/vb/vb_bbs2/200405_04050117.html
を見つけましたが参考になりますか?


やおきな  2005-02-24 18:28:06  No: 119875

このログも同じ症状ですね。
投稿だけで何も解決していないです。

VB.NETのBinaryReaderのバグとしか思えません。
諦めて他の方法でバイナリファイルを扱うことになりそうですね。


おなべ  2005-06-09 01:22:36  No: 119876

はじめまして。
同様の現象が発生しましたが、解決できましたので書き込みます。

結論から書きますと
>        Do While br.PeekChar() <> -1

>        Do While br.BaseStream.Position < br.BaseStream.Length
としたら動作しました。

当方のExceptionの内容です。
{System.ArgumentException}
    [System.ArgumentException]: {System.ArgumentException}
    HelpLink: Nothing
    InnerException: Nothing
    Message: "変換バッファのオーバーフローです。"
    Source: "mscorlib"
    StackTrace: "   at System.Text.UTF8Encoding.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, UTF8Decoder decoder)
   at System.Text.UTF8Decoder.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)
   at System.IO.BinaryReader.InternalReadOneChar()
   at System.IO.BinaryReader.Read()
   at System.IO.BinaryReader.PeekChar()

よくわかりませんが、UTF8へのエンコードで不正なキャラクタがあるようです。
同一のファイルだと同一の場所で発生します。ですので、何バイト目にExceptionが発生するかは元のファイルによります。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加