Dave
2004-10-23 11:26:20 UTC
Hi
All C# ADSI samples that I run cause unspecified errors. If I
translate them into VB.NET they run fine.
Here's an example:
public string getEmail(string LDAPPath, string username)
{
DirectoryEntry entry = new DirectoryEntry(LDAPPath);
DirectorySearcher mySearcher = DirectorySearcher(entry);
mySearcher.PropertiesToLoad.Add("mail");
mySearcher.Filter =
("&(objectClass=user)(sAMAccountName="+username+")");
StringBuilder sb = new StringBuilder();
foreach (SearchResult result in mySearcher.FindAll())
sb.Append(result.Properties["0"].ToString());
return(sb.ToString());
}
results in:
Unspecified error
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException:
Unspecified error
Source Error:
Line 41: StringBuilder sb = new StringBuilder();
Line 42:
Line 43: foreach (SearchResult result in mySearcher.FindAll())
Line 44: sb.Append(result.Properties["0"].ToString());
Line 45:
Source File: c:\inetpub\wwwroot\area51\adsi\webform6.aspx.cs Line:
43
Stack Trace:
[COMException (0x80004005): Unspecified error]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
+704
System.DirectoryServices.DirectoryEntry.Bind() +10
System.DirectoryServices.DirectoryEntry.get_AdsObject() +10
System.DirectoryServices.DirectorySearcher.FindAll(Boolean
findMoreThanOne) +198
System.DirectoryServices.DirectorySearcher.FindAll() +10
area51.ADSI.WebForm6.getEmail(String LDAPPath, String username) in
c:\inetpub\wwwroot\area51\adsi\webform6.aspx.cs:43
area51.ADSI.WebForm6.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\area51\adsi\webform6.aspx.cs:28
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
I'm using "<identity impersonate="true" />" in the web config file.
Any ideas why I can use DirectorySearcher from VB but not from C#?
All C# ADSI samples that I run cause unspecified errors. If I
translate them into VB.NET they run fine.
Here's an example:
public string getEmail(string LDAPPath, string username)
{
DirectoryEntry entry = new DirectoryEntry(LDAPPath);
DirectorySearcher mySearcher = DirectorySearcher(entry);
mySearcher.PropertiesToLoad.Add("mail");
mySearcher.Filter =
("&(objectClass=user)(sAMAccountName="+username+")");
StringBuilder sb = new StringBuilder();
foreach (SearchResult result in mySearcher.FindAll())
sb.Append(result.Properties["0"].ToString());
return(sb.ToString());
}
results in:
Unspecified error
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException:
Unspecified error
Source Error:
Line 41: StringBuilder sb = new StringBuilder();
Line 42:
Line 43: foreach (SearchResult result in mySearcher.FindAll())
Line 44: sb.Append(result.Properties["0"].ToString());
Line 45:
Source File: c:\inetpub\wwwroot\area51\adsi\webform6.aspx.cs Line:
43
Stack Trace:
[COMException (0x80004005): Unspecified error]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
+704
System.DirectoryServices.DirectoryEntry.Bind() +10
System.DirectoryServices.DirectoryEntry.get_AdsObject() +10
System.DirectoryServices.DirectorySearcher.FindAll(Boolean
findMoreThanOne) +198
System.DirectoryServices.DirectorySearcher.FindAll() +10
area51.ADSI.WebForm6.getEmail(String LDAPPath, String username) in
c:\inetpub\wwwroot\area51\adsi\webform6.aspx.cs:43
area51.ADSI.WebForm6.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\area51\adsi\webform6.aspx.cs:28
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
I'm using "<identity impersonate="true" />" in the web config file.
Any ideas why I can use DirectorySearcher from VB but not from C#?