Search
Active

4
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 389622
Opened: 12/25/2008 1:45:52 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
StreamWriterにEncodingを指定してファイル出力を行うと、ファイルサイズが2GBを超える直前で、ArgumentExceptionが発生する。Encodingを指定しない場合は、問題なく出力される。
Details (expand)
製品言語
日本語
バージョン
Visual Studio 2005 SP1
オペレーティング システム
Windows XP
オペレーティング システム言語
日本語
再現の手順
次の様なソースを記述し、実行する。
Imports System.Text
Imports System.IO
Module Module1
Sub Main()
Using sw As New StreamWriter("c:\test.dat", False, Encoding.GetEncoding("shift_jis"))
Dim max As Long = 1024 * 1024 * 1024
For i As Long = 0 To max
sw.Write("12")
Next
End Using
End Sub
End Module
実際の結果
下記の例外が発生:
System.ArgumentException はハンドルされませんでした。
Message="GetBytes() または GetByteCount() を呼び出す前に、Convert() 操作を完了するか、または Encoder.Reset() を呼び出さなければなりません。エンコーダ '日本語 (シフト JIS)' フォールバック 'System.Text.InternalEncoderBestFitFallback'。"
Source="mscorlib"
StackTrace:
場所 System.Text.DBCSCodePageEncoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, EncoderNLS encoder)
場所 System.Text.EncoderNLS.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, Boolean flush)
場所 System.Text.EncoderNLS.GetBytes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, Boolean flush)
場所 System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
場所 System.IO.StreamWriter.Write(String value)
場所 ConsoleApplication1.Module1.Main() 場所 C:\Documents and Settings\xxxx\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Module1.vb:行 10
場所 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
場所 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
場所 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
場所 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
場所 System.Threading.ThreadHelper.ThreadStart()
期待した結果
2GBを超えたファイルを例外無く出力できる
File Attachments
1 attachments
StreamWriter2GBTest.zip
Sign in to post a comment.
Posted by Microsoft on 12/28/2008 at 6:11 PM
フィードバックをお送りいただきまして、ありがとうございます。いただいた報告内容に基づき、現在問題を調査中です。しばらくお待ちください。

Visual Studio Product Team

Problem Description:
When I output a file in StreamWriter specifying Encoding, ArgumentException occurs just before it exceeds 2GB. Without specifying Encoding, it is output properly.

Repro Steps:
Write the followig code, and execute.
Imports System.Text
Imports System.IO
Module Module1

Sub Main()

Using sw As New StreamWriter("c:\test.dat", False, Encoding.GetEncoding("shift_jis"))
Dim max As Long = 1024 * 1024 * 1024
For i As Long = 0 To max
sw.Write("12")
Next
End Using
End Sub

End Module

Actual Results:
The following exception occurs:
System.ArgumentException was unhandled.
Message=" Must complete Convert() operation or call Encoder.Reset() before calling GetBytes() or GetByteCount(). Encoder 'Japanese(Shift JIS)' fallback 'System.Text.InternalEncoderBestFitFallback'."
Source="mscorlib"
StackTrace:
Location System.Text.DBCSCodePageEncoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, EncoderNLS encoder)
Location System.Text.EncoderNLS.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, Boolean flush)
Location System.Text.EncoderNLS.GetBytes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, Boolean flush)
Location System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
Location System.IO.StreamWriter.Write(String value)
Location ConsoleApplication1.Module1.Main()
Location C:\Documents and Settings\xxxx\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Module1.vb: line 10
Location System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
Location System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
Location Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
Location System.Threading.ThreadHelper.ThreadStart_Context(Object state)
Location System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
Location System.Threading.ThreadHelper.ThreadStart()

Expected Results:
Files exceeded 2GB can be output without exceptions.
Posted by Microsoft on 12/28/2008 at 9:50 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 1/4/2009 at 8:37 PM

フィードバックありがとうございます。こちらの件は該当する機能の担当チームにエスカレーションいたしました。今後はそのチーム内でこのバグを次のリリースでフィックスするかどうかを検討いたします。

よろしくお願いします。
Visual Studio Product Team
Posted by Microsoft on 1/6/2009 at 2:21 PM
Thanks again for reporting this issue. This problem has been fixed and the fix will appear in the next major release of the .NET Framework.
Best regards,
Kim Hamilton
Base Class Libraries
Posted by Microsoft on 1/6/2009 at 9:40 PM

こちらの件、ご連絡ありがとうございます。この問題はすでに修正されており.NET Frameworkの次のメジャーリリースでその修正が反映される予定です。

よろしくお願いします、
Kim Hamilton
Base Class Libraries