Link to home
Create AccountLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

System.ArgumentOutOfRangeException'

My code loops through several controls, performing some background searches - some using directoryservices, others may use sql queries.

While it seems to work fine, if I have the immediate window open, I see several back-to-back (seemingly) 'errors' occurring:
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in Microsoft.VisualBasic.dll

Now, as I said, the code works fine, so should I be concerned at all?
All my sql queries are inside a using block, so that should be disposed properly, correct?
And my directory searches occur within a backgroundworker, which I tried placing in a using block as well, but the same 4 'errors' persist...

Any ideas where I can start digging?  
SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of sirbounty

ASKER

Aha.. Bob, that got me thinking about the ds search I was doing.
I have a function that I pass the user account and the AD property to and it returns the value.
For those fields that have no value, they're not even displayed on my form, however that's where the exceptions are occurring.

So, here's the culprit - should I try and rewrite it somehow?
Function GetAttrib(ByVal strUser As String, ByVal strAttrib As String)
  Try
    Return QueryUser(strUser).properties(strAttrib)(0)
  Catch ex As Exception
    Return Nothing 'exception occurs when the property is blank/missing
  End Try
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
No, a searchresult, but I see your point.
Thanx Bob. :^)
My error-free replacement:
Function GetAttrib(ByVal strUser As String, ByVal strAttrib As String) As String
  Dim sr As SearchResult = QueryUser(strUser)
  Dim rpc As ResultPropertyCollection = sr.Properties
  If rpc.Contains(strAttrib) Then Return sr.Properties(strAttrib)(0)
  Return Nothing
End Function

Open in new window