我不断收到错误消息:
System.NullReferenceException:对象引用未设置为对象的实例。
每次我在 IDE 外运行应用程序时,但出于某种神奇的原因,它在 IDE 内运行良好。我确信错误是由这段代码引起的,因为当我删除它时应用程序运行顺利:
Public Function GetCommonFolder() As String
On Error GoTo ErrH
Dim winPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Dim commonfolderpath As String
commonfolderpath = Replace(winPath & "\MyApp Data", "\\", "\")
If My.Computer.FileSystem.DirectoryExists(commonfolderpath) = False Then
System.IO.Directory.CreateDirectory(commonfolderpath)
End If
GetCommonFolder = commonfolderpath
Exit Function
ErrH:
GetCommonFolder = ""
Msgbox("Error retrieving common folder")
End Function
这里有人知道是什么导致了这个烦人的问题吗?