0
我不断收到一个错误:对象引用错误VB.NET
System.NullReferenceException: Object reference not set to an instance of an object.
每次我运行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
有谁知道这里是什么原因造成这个恼人的问题?
哪条线路没有。给出错误? –
更喜欢vb.net风格 – qwr
当我改变这一行:Dim winPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)到一些虚拟值,一切工作正常,出于某种原因。 – user2549990