[mono-vb] FileSystem.FileOpen

Klaus Siebke ksiebke at web.de
Tue May 19 06:30:26 EDT 2009


of course, there is a workaround: use the state of the art
FileStream/StreamReader syntax instead of FileSystem.FileOpen:

Private Sub mnuFileOpentT_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuFileOpentT.Click 
    Dim FileName As String 
    Dim FileNr, fLen As Integer 
    cdlg1.CheckFileExists = True 
    If cdlg1.ShowDialog = Windows.Forms.DialogResult.OK Then 
        FileName = cdlg1.FileName 
' (del) FileNr = FileSystem.FreeFile 
        fLen = CInt(FileSystem.FileLen(FileName)) 
' (del) FileSystem.FileOpen(FileNr, FileName, OpenMode.Input,
OpenAccess.Read, OpenShare.Shared) 
' (new):
        Dim fs As New FileStream(FileName, _
                      FileMode.Open, _
                      FileAccess.Read, _
        Dim sr As New StreamReader(fs)
        Dim myChar(256) as char

' (del) txtImport.Text = FileSystem.InputString(FileNr, fLen) 
' (new):
        sr.read(myChar, 0, flen)
        txtImport.Text = Cstr(myChar)
      Catch ex As Exception 
#If Linux Then 
        LinuxErr(ex, "_frmImportText.mnuFileOpenT_Click") 
        Throw New ApplicationException("_frmImportText.mnuFileOpenT_Click
Error", ex) 
#End If 
' (del)   FileSystem.FileClose(FileNr) 
        End Try 
      End Try 
      'FileNr = modFileFunc.Fileopener(FileName, modFileFunc.READFILE,
      'txtImport.Text = InputString(FileNr, CInt(FileLen(FileName))) 
    End If 

  End Sub

I use FileStream/StreamReader in my Mono VB applications and they run


Andy Hume wrote:
> The cause of this is reported as bug 504791  "NRE in FileSystem.FileOpen
> due to compiler problem"
> (https://bugzilla.novell.com/show_bug.cgi?id=504791)
> A bug in the Mono VB compiler generates bad code in the Mono VB-Runtime
> library which causes the NullRefEx.  So it's not something that's in your
> program's code and I can't immediately see a simple workaround -- well
> apart from changing to .NET's native System.IO classes.  Maybe Rolf can
> suggest another workaround...
> Andy

View this message in context: http://www.nabble.com/FileSystem.FileOpen-tp23565338p23613502.html
Sent from the Mono - VB mailing list archive at Nabble.com.

More information about the Mono-vb mailing list