Determining if instantiated

elitesama

Member
Joined
Dec 14, 2005
Messages
13
Programming Experience
3-5
Hello, I am new to the forums and i did some searching but was unable to locate the answer i am looking for. I am working on a class that works as a intermediary wrapper between vb.net and WMI. Sometimes when i pull a property from a machine on the network, i get an error saying "Object reference not set to an instance of an object". This is mainly because that particular machine does not support the property I am looking for. Now i want to be able to determine if the object variable i am using has been instantiated. I was looking for maybe a IsInstance() method or something of that nature. I've checked out the IsInstanceofType() method but that doesnt do what i want. Any help would be greatly appreciated. Thank you. :)
 
If you want to check whether a reference-type variable refers to an object or not you just have to test whether it Is Nothing or not:
VB.NET:
If myReferenceTypeVariable Is Nothing Then
    MessageBox.Show("The variable does not refer to an object.")
End If
 
jmcilhinney said:
Are you aware that you can use the mgmtclassgen.exe utility to automatically generate .NET classes that correspond to WMI classes?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfmanagementstronglytypedclassgeneratormgmtclassgenexe.asp

I do believe i tried playing with the nothing keyword but i didnt get anywhere with it. The problem is that WMI can return a lot of different datatypes and i declare an object variable to handle this, but if it doesnt return anything it goes crazy on me. Perhaps i can add some checks to it to determine if the class exists first on that computer, and then return the data so that i dont get this error.

As far as mgmtclassgen.exe, i am aware of this yes, but it only generates class information based on the local machines, and i am working with remote computers around the network. Thank you for the link though. :)
 
Back
Top