System.AccessViolationException when calling Active Directory FindAll ()

I have a simple code snippet in C # .Net 4 that randomly gives an access violation when calling .FindAll () in DirectorySearcher in System.DirectoryServices

All that this method does is find out if the user is logged on to Active Directory and return Directory Entry.

I searched the net and can find a few mentions of the exception in SharePoint blogs and forums, but none of the usual C # .net 4 services.

My question is: will there be the same access call to my service, so I need the same fix to solve my problem?

Fix: http://social.technet.microsoft.com/forums/en-US/sharepointadmin/thread/4634f4f4-7857-4de3-9bc5-fcbb946bd8df

The code:

            deSearch.Filter = String.Format("(&(SAMAccountName={0}))", userName);

            using (SearchResultCollection results = deSearch.FindAll())
            {
                if (results.Count > 0)
                {
                    de = results[0].GetDirectoryEntry();
                    return de;
                }
                else
                    return null;
            }

An exception:

System.AccessViolationException: . , . System.DirectoryServices.Interop.UnsafeNativeMethods.IntADsOpen.GetObject(String className, String relativeName) System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName) System.DirectoryServices.DirectoryEntries.Find( )

+3

All Articles