473,698 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryServic es bug?

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.e xample.com", "ou=People,dc=e xample,dc=com") ;

public void example(string server, string ou) {
searcher = new DirectorySearch er(new DirectoryEntry( "LDAP://" + server
+ "/" + ou, "", "", AuthenticationT ypes.ReadonlySe rver));

searcher.Filter = "(uid=wsmit h)";
SearchResultCol lection results = searcher.FindAl l();
Console.WriteLi ne((string)resu lts[0].GetDirectoryEn try().Propertie s["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.exampl e.com/employees/pictures/18273010.JPG".

The error that I'm getting is:
System.Runtime. InteropServices .COMException was unhandled
Message="Unknow n error (0x8000500c)"
Source="System. DirectoryServic es"
ErrorCode=-2147463156
StackTrace:
at
System.Director yServices.Prope rtyValueCollect ion.PopulateLis t()
at
System.Director yServices.Prope rtyValueCollect ion..ctor(Direc toryEntry
entry, String propertyName)
at
System.Director yServices.Prope rtyCollection.P ropertyEnumerat or.get_Entry()
at
System.Director yServices.Prope rtyCollection.P ropertyEnumerat or.get_Current( )
at UserManager.Use rFactory.Find(S tring criteria) in D:\My
Documents\Visua l Studio
2005\Projects\U serManager\User Manager\UserFac tory.cs:line 58
at UserManager.Use rFactory.FindBy Unix(String unix) in D:\My
Documents\Visua l Studio
2005\Projects\U serManager\User Manager\UserFac tory.cs:line 26
at UserManagerTest .Program.Main(S tring[] args) in D:\My
Documents\Visua l Studio
2005\Projects\U serManagerTest\ UserManagerTest \Program.cs:lin e 10
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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

Nov 16 '06 #1
6 5461
>example("ldap. example.com", "ou=People,dc=e xample,dc=com") ;
>
public void example(string server, string ou) {
searcher = new DirectorySearch er(new DirectoryEntry( "LDAP://" + server
+ "/" + ou, "", "", AuthenticationT ypes.ReadonlySe rver));

searcher.Filte r = "(uid=wsmit h)";
SearchResultCo llection results = searcher.FindAl l();
Console.WriteL ine((string)res ults[0].GetDirectoryEn try().Propertie s["gPhotoID"]);
// OFFENDING LINE!
Well, there are two problems here:

1) The "searcher.FindA ll()" call could possibly return no results, if
your filter doesn't match any records - so blindly using "results[0]"
will cause an exception when no result has been returned

2) Along similar lines - even if you have one or multiple results
returned, those possibly will not contain any value in "gPhotoID"
(because the path has not been set), and then using that (by casting
it to a string) will also cause an exception.

Furthermore - if you want to access just a single property (or a few)
on the search result, your best bet is to specify those properties on
the searcher object itself and query them from the result directly
(without having to retrieve the full "DirectoryEntry " object and
access them there).

So your search should look something like this:

searcher.Filter = "(uid=wsmit h)";
// specify which properties to load directly into the result
searcher.Proper tiesToLoad.Add( "gPhotoID") ;

SearchResultCol lection results = searcher.FindAl l();

// check to see if we have any results !
if(results.Coun t 0)
{
SearchResult firstResult = results[0];

// check to see if result contains a value for the property
if(firstResult. Properties.Cont ains["gPhotoID"])
{
// the result's property might be a multi-value
// string property, so pick string [0] from the
// collection
string photoID =
firstResult.Pro perties["gPhotoID"][0].ToString();
}
}

HTH
Marc
Nov 16 '06 #2
Thanks for your reply. I know that it's possible to not get any results
back from searcher.FindAl l(), but I was trying to show the smallest
possible example. I have tried using the ProperitesToLoa d.Add() and
when I do even the properties I don't specify are actually accessible.
Do you know why this would happen? I'll try it again specifying every
property I would like to load, and checking for multiple values for
each property. I just don't understand why that specific property
throws an exception when none of the others do. Could it be the format
that the string is in (in the format for a url?)? Would the length have
to do with it (the length of that property for myself in the directory
is 58 characters)? And what exactly does that exception mean?

Thanks for your help Marc,
Will

Marc Scheuner wrote:
example("ldap.e xample.com", "ou=People,dc=e xample,dc=com") ;

public void example(string server, string ou) {
searcher = new DirectorySearch er(new DirectoryEntry( "LDAP://" + server
+ "/" + ou, "", "", AuthenticationT ypes.ReadonlySe rver));

searcher.Filter = "(uid=wsmit h)";
SearchResultCol lection results = searcher.FindAl l();
Console.WriteLi ne((string)resu lts[0].GetDirectoryEn try().Propertie s["gPhotoID"]);
// OFFENDING LINE!

Well, there are two problems here:

1) The "searcher.FindA ll()" call could possibly return no results, if
your filter doesn't match any records - so blindly using "results[0]"
will cause an exception when no result has been returned

2) Along similar lines - even if you have one or multiple results
returned, those possibly will not contain any value in "gPhotoID"
(because the path has not been set), and then using that (by casting
it to a string) will also cause an exception.

Furthermore - if you want to access just a single property (or a few)
on the search result, your best bet is to specify those properties on
the searcher object itself and query them from the result directly
(without having to retrieve the full "DirectoryEntry " object and
access them there).

So your search should look something like this:

searcher.Filter = "(uid=wsmit h)";
// specify which properties to load directly into the result
searcher.Proper tiesToLoad.Add( "gPhotoID") ;

SearchResultCol lection results = searcher.FindAl l();

// check to see if we have any results !
if(results.Coun t 0)
{
SearchResult firstResult = results[0];

// check to see if result contains a value for the property
if(firstResult. Properties.Cont ains["gPhotoID"])
{
// the result's property might be a multi-value
// string property, so pick string [0] from the
// collection
string photoID =
firstResult.Pro perties["gPhotoID"][0].ToString();
}
}

HTH
Marc
Nov 16 '06 #3
Ok so I tried it again with specifying each property before performing
the search, and checking for multiple results as specified before. I
still get the same exception. I've tried accessing other properties
that are available, but I don't need and I can seem to access those
just fine, but every time I get to this one it throws an exception. Any
Ideas??

Thanks,
Will

bugnthecode wrote:
Thanks for your reply. I know that it's possible to not get any results
back from searcher.FindAl l(), but I was trying to show the smallest
possible example. I have tried using the ProperitesToLoa d.Add() and
when I do even the properties I don't specify are actually accessible.
Do you know why this would happen? I'll try it again specifying every
property I would like to load, and checking for multiple values for
each property. I just don't understand why that specific property
throws an exception when none of the others do. Could it be the format
that the string is in (in the format for a url?)? Would the length have
to do with it (the length of that property for myself in the directory
is 58 characters)? And what exactly does that exception mean?

Thanks for your help Marc,
Will
Nov 16 '06 #4
>Ok so I tried it again with specifying each property before performing
>the search, and checking for multiple results as specified before. I
still get the same exception. I've tried accessing other properties
that are available, but I don't need and I can seem to access those
just fine, but every time I get to this one it throws an exception. Any
Ideas??
Are you still using the ".GetDirectoryE ntry()" call?? This will return
the complete DirectoryEntry for the search result - that will
obviuosly have all the properties available !

Marc
Nov 17 '06 #5
Have you seen this posting: "Errors Reading IBM ITIM LDAP properties"
in microsoft.publi c.adsi.general ? It doesn't exactly apply to your
situation as it's about non-AD LDAP directories but maybe gPhoto*ID is
as poorly handled by the ADSi-.NET conversion as non-AD attributes?

SSG

Nov 22 '06 #6

bugnthecode wrote:
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.e xample.com", "ou=People,dc=e xample,dc=com") ;

public void example(string server, string ou) {
searcher = new DirectorySearch er(new DirectoryEntry( "LDAP://" + server
+ "/" + ou, "", "", AuthenticationT ypes.ReadonlySe rver));

searcher.Filter = "(uid=wsmit h)";
SearchResultCol lection results = searcher.FindAl l();
Console.WriteLi ne((string)resu lts[0].GetDirectoryEn try().Propertie s["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.exampl e.com/employees/pictures/18273010.JPG".

The error that I'm getting is:
System.Runtime. InteropServices .COMException was unhandled
Message="Unknow n error (0x8000500c)"
Source="System. DirectoryServic es"
ErrorCode=-2147463156
StackTrace:
at
System.Director yServices.Prope rtyValueCollect ion.PopulateLis t()
at
System.Director yServices.Prope rtyValueCollect ion..ctor(Direc toryEntry
entry, String propertyName)
at
System.Director yServices.Prope rtyCollection.P ropertyEnumerat or.get_Entry()
at
System.Director yServices.Prope rtyCollection.P ropertyEnumerat or.get_Current( )
at UserManager.Use rFactory.Find(S tring criteria) in D:\My
Documents\Visua l Studio
2005\Projects\U serManager\User Manager\UserFac tory.cs:line 58
at UserManager.Use rFactory.FindBy Unix(String unix) in D:\My
Documents\Visua l Studio
2005\Projects\U serManager\User Manager\UserFac tory.cs:line 26
at UserManagerTest .Program.Main(S tring[] args) in D:\My
Documents\Visua l Studio
2005\Projects\U serManagerTest\ UserManagerTest \Program.cs:lin e 10
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.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
I'm getting the exact same problem. I can read all properties in the
entire directory except for two specific ones which coincidentally were
only recently added to the schema. For those two properties I can't
even enumerate them my loop. As soon as the loop steps to those
properties, boom. Still investigating.

Dec 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2170
by: kovac | last post by:
The System.directoryservices.dll has an error, and this error was described in http://support.microsoft.com/default.aspx?scid=kb;en-us;839424 At the moment we have Framework version v1.0.3705 and I have remove System.directoryservices.dll from current Framework version v1.0.3705. In state of old version I load die new System.directoryservices.dll from the Framework version v1.1.4322. I work with the following function of Joe Kaplan...
12
9610
by: hykim | last post by:
Hello, everyone. according to MSDN, there is any constructor of System.DirectoryServices.SearchResultCollection Class. if I implement DirectorySearcher.FindAll() method by myself, then how can I instanciate SearchResultCollection Class. more clearly, a SearchResult object is created, at the inside of FindAll() method, then how can I put this object into the SearchResultCollection object. there is any method releated to input operation.
1
7375
by: Jason Gleason | last post by:
I am using the following method in a web service that utilizes the system.directoryservices namespace: public ArrayList GetAllAppPools(){ System.DirectoryServices.DirectoryEntry apppools = new DirectoryEntry("IIS://webserver/W3SVC/AppPools"); ArrayList appPoolNames = new ArrayList(); foreach(DirectoryEntry de in apppools.Children) { appPoolNames.Add(de.Name);
1
1722
by: Enosh Chang | last post by:
Hi all, I encounter some problem in DirectoryServices, could someone help me? private void InitLoginUser() { DirectoryEntry objEntry = new DirectoryEntry(); DirectorySearcher objSearcher = new DirectorySearcher(); SearchResult objResult;
0
2534
by: Chris Frohlich | last post by:
All, I've built an Employee Directory with ASP.NET app that queries Active Directory for users and builds links with the results. What I'm seeing is really intermittent failures to bind to the directory. I'll log into the app twice with the same account and sometimes it works, while with others I get the following: System.Runtime.InteropServices.COMException (0x80072020): An operations error occurred at...
9
2142
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group members. It works fine on W2k - machines. It works on a WinNT 4 - server, too, but it stops with a runtime error on any Windows 4.0 Workstation. The error is: System.Runtime.InteropServices.COMException 0x800500F. at...
2
5456
by: Kelvin | last post by:
Hello I am using web matrix develop a login page through Active Directory but I cannot figure out why it is giving me an error when importing system.directoryServices. Any help will do! thank Compiler Error Message: BC30466: Namespace or type 'DirectoryServices' for the Imports 'System.DirectoryServices' cannot be found Line 2: Imports System.Tex Line 3: Imports System.Collection Line 4: Imports System.DirectoryService Line 5:
5
2064
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our Active Directory on a web page. If I can connect to the AD interfaces, then I think I can handle it from there. I do have a VS.NET C# project successfully working and enumerating names,
7
2926
by: turbon | last post by:
Hello, I am writing code, which will copy webServices from one IIS 6.0 webserver to another and using DirentoryServices to achieve this purpose. And I have problems with authentication - I get an error whenever I try to read properties of DirectoryEntry object. I had same problems when I was using WMI, but there setting ConnectionOptions co = new ConnectionOptions(); co.Authentication = AuthenticationLevel.PacketPrivacy; solved the...
7
16325
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I am using this code to get groups for a user and getting a error (5) on the GetAuthorizationGroups() function . There are two domains. This function works on the local domain but does not work on the other domain. Other functions work on the other domain like get all the users and get all the groups and I can validate users on the other domain so I think I am communciating with the other domain OK just not with the...
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.