Active Directory Objects - Object reference not set to an instance of an object.

J

Jason Dunbar

Whilst creating a class to search Active Directory domains and
retrieve user details, I ran into the following error:-

Object reference not set to an instance of an object.

Here's the error log:

Source Error:


Line 79: StringBuilder summary
= new StringBuilder();
Line 80:
Line 81:
System.DirectoryServices.SearchResultCollection results =
System.DirectoryServices.SearchResultCollection();
Line 82: searcher.FindAll();
Line 83: }


Source File: c:\inetpub\dev2\adsearch\webform1.aspx.cs Line: 81

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]

System.DirectoryServices.Interop.IDirectorySearch.ExecuteSearch(String
pszSearchFilter, String[] pAttributeNames, Int32 dwNumberAttributes,
IntPtr& hSearchResult) +0
System.DirectoryServices.DirectorySearcher.FindAll(Boolean
findMoreThanOne)
System.DirectoryServices.DirectorySearcher.FindAll()
adsearch.WebForm1.btnSearch_Click(Object sender, EventArgs e) in
c:\inetpub\dev2\adsearch\webform1.aspx.cs:81
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


I've tried several ways of doing this, and according to every
reference I have read (Including the C# book in front of me, which
uses EXACTLY the same method of returning the AD Search results)

If anyone could shed some light on why it's not behaving as expected,
I would be most greatful. Thanks.

- Jason
 
W

Willy Denoyette [MVP]

Please post a larger part of the code, especially the part that initializes
the searcher reference as it happens to be null.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top