I have deployed a feature (wsp) on our new production server but get the following error:

error CS0234: The type or namespace name 'DirectoryServices' does not exist in the namespace 'System'

The feature had been working fine on the test system. Have I forgotten something? Does deploying directly from VS2010 do something different than deploying by hand?

More Information The feature is a replacement for the smallSearchBox. The error message is written to the log and my search box does not appear. The deployment in test is done via VS2010. In production the WSP is copied and installed by hand.

  • 1
    DirectoryServices is in System.DirectoryServices.dll, what are the properties of the assembly reference in your project. location, version etc
    – djeeg
    Commented Apr 20, 2011 at 10:02
  • @djeeg - C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll
    – paul
    Commented Apr 20, 2011 at 10:08
  • Copy the above DLL to bin folder of the application and see if it solved. Then add this to WSP and deploy it.
    – Shoban
    Commented Apr 20, 2011 at 12:56
  • I added System.DirectoryService reference for my assembly as well. Does any has solid solution or a work aoround for the above problem? if yes please let me know.
    – user3233
    Commented Apr 29, 2011 at 13:12
  • This might be a dumb question... but is .NET 2.0 installed on the new server?
    – Kit Menke
    Commented Apr 29, 2011 at 13:40

4 Answers 4


That looks like a compiler error. Are you trying to do your deployment to production from within Visual Studio? To deploy to a system other than your development environment you should use the wsp file. Copy the wsp and install it on your server using Powershell or stsadm on one of the servers in your farm.

It looks as though you are trying to build on the production server, and your environment is probably not set up right. Installing Visual Studio on your production system is not recommended.

  • No, we are not building on the production system. But perhaps that is the problem. What does VS2010 do automatically on the test system that we have to do by hand on the production system? e.g. set Safe assemblies etc
    – paul
    Commented Apr 20, 2011 at 11:30
  • Okay, are you trying to deploy to production using Visual Studio? Safe controls should be configured by your solution/feature. I am still confused as this does not look like a run-time error message.
    – SPDoctor
    Commented Apr 20, 2011 at 12:52
  • Just added some more info to my question...
    – paul
    Commented Apr 21, 2011 at 6:12

This may be a simplistic answer so apologies. But if you are referencing it from an Application Page, do ensure that you have System.DirectoryServices added in the references for your Assembly!


I agree with SPDoctor - it looks like a compiler error. Where do you get the error from (browser, console, visual studio, etc) and what did you do exactly to get the error? When you deploy to a production server, all you need is the WSP. At that stage it should have already compiled your code into DLLs. These DLLs should be contained inside your WSP, so no compilation should take place on the production server, unless you are deploying .cs files along with your aspx files in the _layouts folder and your pages are being compiled at runtime (which I wouldn't recommend)?

  • Just added some more info to my question...
    – paul
    Commented Apr 21, 2011 at 6:12

I ran into a similar problem with a Application page and I resolved it by adding an entry into the assemblies section of the web config. Try adding DirectoryServices as an entry.

  • Mike, can expand on how to do that? I'm getting the same error. I get this error when I can my code from "CodeBehind" to "CodeFile" How do I fix this?
    – user6800
    Commented Feb 8, 2012 at 16:29
  • If you edit the web config for your web application and search for the section <assemblies> you should be able to add an entry <add assembly="System.DirectoryServices, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> and the error should go away
    – Mike Polen
    Commented Feb 8, 2012 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.