I have recently learned how to retreive information from AD with VB in an ASP.NET application so that i can do some group comparison and i am receiving the
System.OutOfMemoryException in the below code. I have spent 3 days or so looking for solutions and everything i have tried doesn’t seem to work. My
machine is not out of actual memory so i am at a loss. Can someone point me in the right direction please? Thank you in advance for your assistance.
Dim Domain As New DirectoryEntry("GC://dc=XXX,dc=XXX,dc=XXX")
Dim DSearcher As New DirectorySearcher(Domain)
Dim pSearcher As New DirectorySearcher(Domain)
pSearcher.PropertiesToLoad.Add("memberOf")
pSearcher.PropertiesToLoad.Add("cn")
pSearcher.Filter = ("(mail=" & txtUser.Text & "@domain.com)")
Dim pResults As SearchResult
pResults = pSearcher.FindOne()
Dim propcount = pResults.Properties("memberOf").Count
Dim dn As String
Dim equalsIndex As Integer
Dim commaIndex As Integer
Dim propcounter As Integer = 0
Dim groupnames As New StringBuilder
Try
While propcounter < propcount
dn = pResults.Properties("memberOf")(propcounter)
equalsIndex = dn.IndexOf("=", 1)
commaIndex = dn.IndexOf(",", 1)
If equalsIndex = -1 Then
End If
groupnames.Append((dn.Substring((equalsIndex + 1).ToString, (commaIndex - equalsIndex) - 1)))
groupnames.Append("|")
End While
Catch ex As Exception
MsgBox("Error Obtaining Group Names. " & ex.Message)
End Try
Label1.Text = groupnames.ToString
As your are using while to go through the search result , but I cannot find a increasing of propcounter, it may cause the group names increases till it exhaust all memory.
jordanbmail
Member
13 Points
13 Posts
System.outofmemoryexception when Parsing 'memberOf'
Aug 23, 2011 10:19 PM|LINK
Greetings,
I have recently learned how to retreive information from AD with VB in an ASP.NET application so that i can do some group comparison and i am receiving the
System.OutOfMemoryException in the below code. I have spent 3 days or so looking for solutions and everything i have tried doesn’t seem to work. My
machine is not out of actual memory so i am at a loss. Can someone point me in the right direction please? Thank you in advance for your assistance.
Dim Domain As New DirectoryEntry("GC://dc=XXX,dc=XXX,dc=XXX") Dim DSearcher As New DirectorySearcher(Domain) Dim pSearcher As New DirectorySearcher(Domain) pSearcher.PropertiesToLoad.Add("memberOf") pSearcher.PropertiesToLoad.Add("cn") pSearcher.Filter = ("(mail=" & txtUser.Text & "@domain.com)") Dim pResults As SearchResult pResults = pSearcher.FindOne() Dim propcount = pResults.Properties("memberOf").Count Dim dn As String Dim equalsIndex As Integer Dim commaIndex As Integer Dim propcounter As Integer = 0 Dim groupnames As New StringBuilder Try While propcounter < propcount dn = pResults.Properties("memberOf")(propcounter) equalsIndex = dn.IndexOf("=", 1) commaIndex = dn.IndexOf(",", 1) If equalsIndex = -1 Then End If groupnames.Append((dn.Substring((equalsIndex + 1).ToString, (commaIndex - equalsIndex) - 1))) groupnames.Append("|") End While Catch ex As Exception MsgBox("Error Obtaining Group Names. " & ex.Message) End Try Label1.Text = groupnames.ToStringXiaoCheng Fa...
All-Star
17743 Points
1414 Posts
Re: System.outofmemoryexception when Parsing 'memberOf'
Aug 25, 2011 03:35 AM|LINK
Hi,
As your are using while to go through the search result , but I cannot find a increasing of propcounter, it may cause the group names increases till it exhaust all memory.
I hope this can be helpful for you.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
jordanbmail
Member
13 Points
13 Posts
Re: System.outofmemoryexception when Parsing 'memberOf'
Aug 25, 2011 04:21 PM|LINK
Nice! Thanks! That fixed it. Just needed a fresh pair of eyes. Thanks again!!!!!!