PDA

Click to See Complete Forum and Search --> : VS 2010 IDE crashes using this class


Blupig
Feb 11th, 2011, 04:53 PM
This class, along with a few others prominent in my projects, crashes the VS IDE:


Public Class IO
Public Shared Function OpenString(ByVal FilePath As String) As String
Try
Dim objReader As New System.IO.StreamReader(FilePath)
Dim ret As String = objReader.ReadToEnd
objReader.Close()
Return ret
Catch ex As Exception
Return Nothing
End Try
End Function

Public Shared Sub SaveString(ByVal FilePath As String, ByVal SourceString As String)
On Error Resume Next
FileIO.FileSystem.WriteAllText(FilePath, SourceString, False)
End Sub

Public Shared Function FolderExists(ByVal FolderPath As String) As Boolean

Dim f As New System.IO.DirectoryInfo(FolderPath)
Return f.Exists

End Function

Public Shared Sub LoadList(ByRef ListObject As Object, ByVal FilePath As String)
Dim r As System.IO.StreamReader
r = New System.IO.StreamReader(FilePath)
While (r.Peek() > -1)
ListObject.Items.Add(r.ReadLine)
End While
r.Close()

End Sub

Public Shared Sub SaveList(ByVal ListObject As Object, ByVal FilePath As String)

Dim w As System.IO.StreamWriter
Dim i As Integer
w = New System.IO.StreamWriter(FilePath)
For i = 0 To ListObject.Items.Count - 1
w.WriteLine(ListObject.Items.Item(i))
Next
w.Close()

End Sub

Public Shared Sub ListFiles(ByRef L As Object, ByVal folderpath As String, Optional ByVal extension As String = "*.dll")

Try
Dim DirInfo As New DirectoryInfo(folderpath)
Dim FileInfoArray() As FileInfo = DirInfo.GetFiles(extension)
Dim FileInfo As FileInfo

Dim FileCount As Integer = 0
For Each FileInfo In FileInfoArray
FileCount = FileCount + 1
L.Items.Add(FileInfo.Name)

Next
Catch ex As Exception
ErrMsg()
End Try

End Sub

End Class


What the hell is wrong? I've tried just about everything from compatibility mode to admin to a couple registry edits...I've even reinstalled and am seriously considering a reformat. It does the same on my friend's VS. Apparently it's LoadList that does it in this particular class, but as I said before, a couple of my modules/classes in various other projects also pose the same issue, even without LoadList.

Sorry if this is the wrong section.

techgnome
Feb 11th, 2011, 04:57 PM
It's your class name... at least that's the first thing that jumped out at me. It maybe conflicting with the built-in IO namespace that's already part of the .NET Framework.

-tg

Blupig
Feb 15th, 2011, 03:28 PM
It's your class name... at least that's the first thing that jumped out at me. It maybe conflicting with the built-in IO namespace that's already part of the .NET Framework.

-tg

A friend and I have actually resolved it, it's a pretty big bug in the IDE. Sometimes (note: not always) when trying to view a class with a direct-object as an argument in a method, the IDE crashes. So, in this specific class, I had to change the Object argument in the LoadList method to an IList object.

Thanks for replying, though :)

techgnome
Feb 15th, 2011, 03:54 PM
"Sometimes (note: not always) when trying to view a class with a direct-object as an argument in a method, the IDE crashes." -- uuuuh... WHAT? I didn't follow... what do you mean "direct object"...

-tg

techgnome
Feb 15th, 2011, 03:58 PM
FYI - I copied your code.... changing only two lines, I got it to compile just fine... so I'm not sure what you're doing that's causing the crash.

-tg

Nightwalker83
Feb 15th, 2011, 07:27 PM
FYI - I copied your code.... changing only two lines, I got it to compile just fine... so I'm not sure what you're doing that's causing the crash.

-tg

Maybe you should tell us which two lines you changed in the original code?

techgnome
Feb 15th, 2011, 09:12 PM
I imported the IO namespace... and commented out the call to the ErrMsg() function as it wasn't in the code. That's it.

Now, I said it compiled... didn't actually make any calls to it... since I'm not sure how it was being called or used...

-tg