A StringBuilder buffer has been overflowed by unmanaged code.

Warning: A StringBuilder buffer has been overflowed by unmanaged code.  The process may become unstable.  Insufficient capacity allocated to the StringBuilder before marshaling it.

i get this when i get last line in chat room

any suggestion to fix

13 thoughts on “A StringBuilder buffer has been overflowed by unmanaged code.

  1. this is the code im using

    Dim iLineIndex As Integer = SendMessage(hwnd, EM_LINEINDEX, ilastLine, 0)
    Dim iLineLength As Integer = SendMessage(hwnd, EM_LINELENGTH, iLineIndex, 0)
    if iLineLength = 0 return Nothing ' or return ""
    Dim sb As StringBuilder = New StringBuilder(iLineLength)
    sb.Append(ChrW(iLineLength))
    sb.Length = iLineLength
    SendMessage(hwnd, EM_GETLINE, ilastLine, sb)
    
  2.     Declare Unicode Function SendMessage Lib "USER32" Alias "SendMessageW" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As StringBuilder) As Integer
    
        Declare Auto Function SendMessage Lib "USER32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    
  3. that is the exception i get

    Warning: A StringBuilder buffer has been overflowed by unmanaged code.  The process may become unstable.  Insufficient capacity allocated to the StringBuilder before marshaling it.

  4. Yes catch it and check all relevant parameters in code.

    Try
        SendMessage(hwnd, EM_GETLINE, ilastLine, sb)
    Catch ex As Exception
        MsgBox("SendMessage failed " & ex.Message)
    End Try

    Set breakpoint at MsgBox

Leave a Reply

You must Register or Login to comment on A StringBuilder buffer has been overflowed by unmanaged code.