Search

DirectoryEntry.Exists() throws exception for non-existent WinNT object by Jay Logue

Closed
as Won't Fix Help for as Won't Fix

0
0
Sign in
to vote
Type: Bug
ID: 337682
Opened: 4/10/2008 11:27:35 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Contrary to the documentation the System.DirectoryServices.DirectoryEntry.Exists() method throws a COMException when presented with a path to a non-existent object using the WinNT provider (e.g. “WinNT://MyComputer/NoSuchUser,user”). The COMException complains about the target object not being found (e.g. “The user name could not be found.”).

As the point of the Exists() method is to test for the existence of an object without the need to catch an Exception, the code is clearly buggy.
Details (expand)
Product Language
English

Version

.NET Framework 3.0
Operating System
Windows XP Professional
Operating System Language
English
Steps to Reproduce
Run the following program:

using System;
using System.DirectoryServices;

public class TestProgram
{
    public static void Main(string[] args)
    {
        bool result = DirectoryEntry.Exists("WinNT://" + Environment.MachineName + "/NoSuchUser,user");
        Console.WriteLine("result is {0}", result);
    }
}
Actual Results
Unhandled Exception: System.Runtime.InteropServices.COMException (0x800708AD): The user name could not be found.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Exists(String path)
at TestProgram.Main(String[] args)
Expected Results
False
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

Sign in to post a comment.
Posted by Microsoft on 4/2/2009 at 11:34 AM
Jay, Thanks for your feedback. We are resolving this bug as won't fix.
Although the design isn't right... Apps might have been written expecting this - and the change might break those apps. The workaround is to catch the exception - not pretty, agreed, but not enough justification for a fix.
The documentation needs to be fixed and I will open a doc workitem for this.
Posted by Microsoft on 4/10/2008 at 8:33 PM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team
Sign in to post a workaround.