PC Review


Reply
Thread Tools Rate Thread

Bug in ActiveDirectory access of .NET Framework

 
 
Marco Herrn
Guest
Posts: n/a
 
      13th Apr 2005
Hi,

I have an application in C# that manages users, shares and printers in
the AD. This application sometimes runs on an error accessing the AD.
This is not really reproducable, it happens often, but not always.
Sometimes it runs on an error and later goes over the same code again
and works. The error message is always a NullReferenceException on
System.DirectoryServices.Interop.IAds.GetEx, for example:

at System.DirectoryServices.Interop.IAds.GetEx(String bstrName)
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyCollection.get_Item(String
propertyName)
at amt.user.UserManagement.getUserByDirectoryEntry(DirectoryEntry
ADEntry) in c:\inetpub\wwwroot\amt\sharp\user\UserManagement.cs:line 2098
at amt.user.UserManagement.getUserByProperty(String Property, String
domain) in c:\inetpub\wwwroot\amt\sharp\user\UserManagement.cs:line 1900
at amt.user.UserManagement.getUserBySAM(String SAM, String domain)
in c:\inetpub\wwwroot\amt\sharp\user\UserManagement.cs:line 576
at replication.RootDSEReplicator.checkUserReplicationStatus(AddEntry
entry) in
c:\inetpub\wwwroot\amt\sharp\replication\RootDSEReplicator.cs:line 284
at replication.RootDSEReplicator.checkReplicationStatus(Object
state) in
c:\inetpub\wwwroot\amt\sharp\replication\RootDSEReplicator.cs:line 244

I haven't seen any pattern when this happens. The NulRef obviously
doesn't happen in my code. It seems to happen in one case on this action:

if(ADEntry.Properties["distinguishedName"].Value != null){
newUser.DN= ADEntry.Properties["distinguishedName"].Value.ToString();
}

Any ideas what can cause this? What surprises me is, that the NullRef
isn't thrown by my code, but from inside IAds.

Regards
Marco
 
Reply With Quote
 
 
 
 
Marc Scheuner [MVP ADSI]
Guest
Posts: n/a
 
      14th Apr 2005
>I haven't seen any pattern when this happens. The NulRef obviously
>doesn't happen in my code. It seems to happen in one case on this action:
>
>if(ADEntry.Properties["distinguishedName"].Value != null){
> newUser.DN= ADEntry.Properties["distinguishedName"].Value.ToString();


The NullRef DOES happen in your code !!!

If your entry does NOT contain a value for "distinguishedName", then
the ADEntry.Properties["distinguishedName"] will be NULL, and
trying to access its .Value property will result in that error.

You need to check like this:

if(ADEntry.Properties.Contains("distinguishedName").....
{ // do something, like accessing the .Value property }

or

if(ADEntry.Properties["distinguishedName"] != null)
{ // do something, like accessing the .Value property }

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activedirectory - get objectschemas? Peter Widmer Microsoft Dot NET Framework 0 27th Dec 2005 03:19 PM
Loggign ActiveDirectory-Access Ruth Thieme Microsoft Windows 2000 Security 0 13th Sep 2005 03:16 PM
importing ActiveDirectory data into a access table Megabyte Microsoft Access External Data 0 9th Mar 2005 03:37 PM
Reinstall ActiveDirectory only adeveloper Microsoft Windows 2000 Networking 5 23rd Dec 2004 11:05 AM
Get UserPassword in ActiveDirectory ruca Microsoft VB .NET 3 13th Jul 2004 03:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 PM.