[Mono-dev] Active Directory issues

Ron Davis r.ronald.davis at gmail.com
Thu Aug 12 22:23:09 EDT 2010

I am currently porting an application to Mono that requires Active Directory
integration, but can't seem to get the same code base to run under .NET 3.5
and Mono. I am using Mono 2.6.4, but I've also tried a build of 2.6.7. For
example, if I want to fetch the defaultNamingContext, I can do it in .NET

 using (DirectoryEntry de = new DirectoryEntry())
                    de.AuthenticationType = AuthenticationTypes.Anonymous;
                    de.Path = "LDAP://";

                    _defaultNamingContext =

However, under Mono, this fails with an LdapException

Cause: LDAP Error Message: 0000208F: NameErr: DSID-031001F7, problem 2006
(BAD_NAME), data 8350, best match of:'rootDSE'
Error Message: Invalid DN Syntax
ResultCode: 34

Instead, I can get it working under Mono with:

using (DirectoryEntry de = new DirectoryEntry())
     de.AuthenticationType = AuthenticationTypes.Anonymous;
     de.Path = "LDAP://";

      using (DirectorySearcher deSearch = new DirectorySearcher())
           deSearch.SearchRoot = de;
           deSearch.SearchScope = System.DirectoryServices.SearchScope.Base;

           using (SearchResultCollection src = deSearch.FindAll())
                foreach (SearchResult sr in src)
                     ResultPropertyValueCollection rpvc =
                          if (rpvc != null)
                               _defaultNamingContext = rpvc[0].ToString();

but this fails in .NET with System.Runtime.InteropServices.COMException,
"The specified directory service attribute or value does not exist.

Is there an easy way around this?

Should I just abandon System.DirectoryServices and instead just use

The AD server is running Windows 2008 R2.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100812/7c31d921/attachment-0001.html 

More information about the Mono-devel-list mailing list