Hi, I'm building a small desktop app in VS Std 2005 with C# and .net
2.0. I've managed to get the code together to query the ldap my company
has, but every time I attempt to access a specific property a COM
Exception gets thrown, and I can't figure out why. This is a desktop
app.
example("ldap.example.com", "ou=People,dc=example,dc=com");
public void example(string server, string ou) {
searcher = new DirectorySearcher(new DirectoryEntry("LDAP://" + server
+ "/" + ou, "", "", AuthenticationTypes.ReadonlyServer));
searcher.Filter = "(uid=wsmith)";
SearchResultCollection results = searcher.FindAll();
Console.WriteLine((string)results[0].GetDirectoryEntry().Properties["gPhotoID"]);
// OFFENDING LINE!
}
So that's pretty much the smallest bit of code I can use and get the
error. All the other properties I've tried to access so far have worked
just fine, I've even found some properties to be a collection of values
which works just fine. The gPhotoID should contain a url to a picture
which would look like
"http://intranet.example.com/employees/pictures/18273010.JPG".
The error that I'm getting is:
System.Runtime.InteropServices.COMException was unhandled
Message="Unknown error (0x8000500c)"
Source="System.DirectoryServices"
ErrorCode=-2147463156
StackTrace:
at
System.DirectoryServices.PropertyValueCollection.P opulateList()
at
System.DirectoryServices.PropertyValueCollection.. ctor(DirectoryEntry
entry, String propertyName)
at
System.DirectoryServices.PropertyCollection.Proper tyEnumerator.get_Entry()
at
System.DirectoryServices.PropertyCollection.Proper tyEnumerator.get_Current()
at UserManager.UserFactory.Find(String criteria) in D:\My
Documents\Visual Studio
2005\Projects\UserManager\UserManager\UserFactory. cs:line 58
at UserManager.UserFactory.FindByUnix(String unix) in D:\My
Documents\Visual Studio
2005\Projects\UserManager\UserManager\UserFactory. cs:line 26
at UserManagerTest.Program.Main(String[] args) in D:\My
Documents\Visual Studio
2005\Projects\UserManagerTest\UserManagerTest\Prog ram.cs:line 10
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I can't seem to find a solution. I've been googling for over an hour,
and most of the answers I find pertain to credential issues, and
asp.net issues. Can someone please offer assistance?
Thanks,
Will