Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No line # neither Sub reported with "Object reference not set to an instance of an object"

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
566
0
16
US
Colleagues,
Here's the error message I receive:

"Currently logged Users:
Error occurred in
on Line #, error description:
Object reference not set to an instance of an object."

Supposedly, it comes from this code:

Code:
'====================================================================================================================================
Public Function GetUserNames() As String
'====================================================================================================================================
Dim lsLogStr As String = ""

' Let's get digging! But keep in mind that if it's a network server, it might be unavailable, hence Try-Catch-EndTry construct.
Try
	Dim lcMachineName As String = "\\" + AddBackSlash(CharTran(gcMachineName, "\", ""))
	Dim loSearcher As New System.Management.ManagementObjectSearcher(lcMachineName + "root\cimv2", "SELECT * FROM Win32_ComputerSystem")
	Dim loQueryCollection As ManagementObjectCollection = loSearcher.Get()

	For Each loQueryObj As ManagementObject In loQueryCollection
		lsLogStr += loQueryObj("UserName").ToString() + vbCrLf
	Next
Catch loErr As Exception
	lsLogStr = Read_Exception(loErr)
	If Strings.Left(lsLogStr, 2) <> vbCrLf Then lsLogStr += vbCrLf
	My.Computer.FileSystem.WriteAllText(gsLogFile, lsLogStr, true)
End Try

Return lsLogStr

End Function
'====================================================================================================================================

Here's the Read_Exception() code (Str_Extract() is my roll-er-own simulation of the STREXTRACT() built-in function in the ol' good VFP):

Code:
'====================================================================================================================================
Public Function Read_Exception(ByVal toErr As Exception) As String
'====================================================================================================================================
Dim lsErrMsg As String = "", lsMsg As String = toErr.Message, lsStackTrace As String = toErr.StackTrace, lsInProc As String = "",
	 lsLineNo As String = ""

lsInProc = Str_Extract(lsStackTrace, " at ", " in ", 2, 1)
lsLineNo = Str_Extract(lsStackTrace, ":line ", "", 1, 1)
lsErrMsg = "Error occurred in " & lsInProc & vbCrLf & "on Line #" & lsLineNo & ", error description: " & vbCrLf & lsMsg

Return lsErrMsg
End Function
'====================================================================================================================================

Unless I'm gravely mistaken, the toErr.StackTrace contains nothing... but what might cause that?

AHWBGA!

Footnote: Insult to injury, this error happens only when I run compiled EXE on a server box. On my WS it works properly.


Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top