[mono-vb] FileSystem.FileOpen

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


Hi,

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 
      Try 
        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, _
                      FileShare.ReadWrite)
        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)
        sr.close
        fs.close
         
      Catch ex As Exception 
#If Linux Then 
        LinuxErr(ex, "_frmImportText.mnuFileOpenT_Click") 
#Else 
        Throw New ApplicationException("_frmImportText.mnuFileOpenT_Click
Error", ex) 
#End If 
      Finally 
        Try 
' (del)   FileSystem.FileClose(FileNr) 
        Catch 
        End Try 
      End Try 
      'FileNr = modFileFunc.Fileopener(FileName, modFileFunc.READFILE,
False) 
      'txtImport.Text = InputString(FileNr, CInt(FileLen(FileName))) 
      'FileClose(FileNr) 
    End If 

  End Sub


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

//Klaus


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