MattOverton MattOverton - 1 year ago 140
Vb.net Question

vb.net Adding multi-valued string active directory query result to ArrayList object

I'm struggling with a System.NullReferenceException error when trying to store the results of an Active Directory query in an ArrayList.

I don't understand what I'm doing wrong. My query is fetching the proxyAddresses attribute from a single AD account, then I use the following code to try to put that into an ArrayList I defined earlier:

For Each proxyAddr As String In result.Properties("proxyAddresses")
proxyArrayList.Add(proxyAddr.Substring(0))
Next


This doesn't seem to work and the ArrayList remains empty even though I know there are valid results. I know this because the following works perfectly:

For Each proxyAddr As String In result.Properties("proxyAddresses")
proxyListBox.Items.Add(proxyAddr.Substring(0))
Next


I'm sure I'm being daft, but I'm still trying to learn. Any help would be greatly appreciated.

Answer Source

I guess you declared proxyArrayList like this:

Dim proxyArrayList As ArrayList

But you need to instantiate the ArrayList:

Dim proxyArrayList As New ArrayList
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download