.NET Application crashes

In the sample code , show below, we are merging many binary file to a single mp3 file. This process works fine for 4 times , but on the 5th time, the application crashes on br.Read without throwing any .net error. We have implemented try catch blocks also.It gives the system error &H80131315& 

Dim fsInput As System.IO.FileStream

Dim fsOutput As System.IO.FileStream

Dim bw As BinaryWriter

Dim br As BinaryReader

Dim sMergeFiles() As String

Dim iCount As Short

Dim bytBuffer() As Byte = New Byte() {}

Dim lFileSize As Long

Dim sMergedFile As String

Try

sMergeFiles = alsFileToBeMerged

sMergedFile = sOutputFileName

If File.Exists(sMergedFile) Then File.Delete(sMergedFile)

fsOutput = New FileStream(sMergedFile, FileMode.CreateNew, FileAccess.ReadWrite)

bw = New BinaryWriter(fsOutput)

For iCount = 0 To sMergeFiles.Length - 1

If sMergeFiles(iCount) <> "" Then

lFileSize = FileSize(sMergeFiles(iCount))

fsInput = New FileStream(sMergeFiles(iCount), FileMode.Open, FileAccess.Read)

br = New BinaryReader(fsInput)

br.BaseStream.Seek(0, SeekOrigin.Begin)

ReDim bytBuffer(lFileSize - 1)

br.Read(bytBuffer, 0, bytBuffer.Length)

bw.Write(bytBuffer)

fsOutput.Flush()

br.Close()

fsInput.Close()

Else

Exit For

End If

Next

fsOutput.Close()

bw.Close()

Catch

Finally

fsOutput = Nothing

bw = Nothing

br = Nothing

fsInput = Nothing

End Try

 

 

 



Answer this question

.NET Application crashes

  • Jimski

    Well you wouldn't even know if you WERE getting an exception because your catch statment doesn't do anything. So you could be getting exceptions like crazy telling you why it's not working.

  • snamburu

    Hello,

    Do you use BinaryReader's PeekChar() or ReadChar() methods anywhere in your code The surrogate description on the exception is usually generated when these methods are used. Is it possible to get a small repro for the problem pl.

    Thanks

    Lakshan Fernando

    BCL Team



  • Visual Martin

    Hi Philippe Dufour,

    We have a put a messagebox in the catch block. The application run fine 4 times, and on the 5th occasion , the application crashes without showing any messagebox.


  • Bojidar Markov

    We are not getting any exception. Also , the application crashes on br.Read() line in the code.
  • buzzbuba

    Could you paste the exception message you get when you put the MessageBox in the catch statement

    I'm sure it would help us find the problem you have with br.Read


  • Arnak

    What kind of exeption do you get and on wish line of code, provide more information please.

  • Arunachalam

    And, as a matter of reference, what is the exception message you get with the original code
  • elygp

    Hi Philippe Dufour,

          Thanks for your reply. We are reading binary file, so when I tried your code,it gave error

    Additional information: Found a low surrogate char without a preceding high surrogate at index: 223. The input may not be in this encoding, or may not contain valid Unicode (UTF-16) characters.

     


  • Jens Sauer

    Just tried your code.

    Works fine here, no exception, nothing.

    The only change I did was with the FileSize function. I had to use FileLen (didn't find in which assembly, .Net 1.1, to find it).

    Just a little comment, you could also use the StreamReader / StreamWriter for your code.

    Public Sub TransfererDonnees(ByVal FileNames As ArrayList, ByVal ExitFile As String)

    Dim sRead As StreamReader
    Dim sWrite As New StreamWriter(ExitFile)

    Dim Ligne As String
    Dim Counter As Integer

    While Compteur < FileNames.Count
        sRead =
    New StreamReader(CType(FileNames(Counter), String))

        Ligne = sRead.ReadToEnd()

        sWrite.WriteLine(Ligne)

        sRead.Close()
        Compteur += 1
    End While

    sWrite.Close()


  • Richard Moorhouse

    Yes, when have put an Msgbox inside catch statement. But still the application crashes on br.Read() statement.
  • .NET Application crashes