System.DirectoryServices Unknown error (0x80005000) Resolution

Comments 0

Share to social media

This seems completely ridiculous.  I needed to write some queries against Active Directory so I made a quick console application to thresh things out before putting them inside SharePoint.  After getting everything working, I dropped it into a web part and deployed it out to our test server.  After setting up the LDAP connection on the web part (I made them editable properties instead of hardcoding them) I ended up getting the following obscure error:

COM Exception was unhandled
Unknown error (0x80005000)
Error Code: -2147463168
Source: System.DirectoryServices

At first I was thinking it was a SharePoint induced security problem and was expecting a long and arduous road of getting everything working.  However, after finding a random comment in a forum it turns out this is really simple issue with a terrible error message. 

Resolution:

Capitalize LDAP:// in the connection string.

It turns out I accidentally did everything right in the console app but failed to do it again when configuring my web part.  I’m glad I found this now instead of running into it while deploying it to production.  What I decided to do was just add this code to the set section of my web part property:

Regex.Replace(value, “ldap://”, “LDAP://”, RegexOptions.IgnoreCase);

It uses a regular expression to locate ldap:// in the connection string regardless of how it is spelled (Ldap, LDap, ldaP, etc) and replaces it with the fully uppercased version. Pretty easy fix.

Load comments

About the author

Damon Armstrong

See Profile

Damon Armstrong is a consultant with SystemwarePS in Dallas, Texas. He is also a blogger and author of Pro ASP.NET 2.0 Website Programming and SharePoint 2013 Essentials for Developers. He specializes in the Microsoft stack with a focus on web technologies like MVC, ASP.NET, JavaScript, and SharePoint. When not staying up all night coding, he can be found watching a bunch of kids, studying Biblical topics, playing golf, or recovering from staying up all night coding.