System.DirectoryServices is not recognised in the

2019-03-14 09:29发布

I'm trying to use System.DirectoryServices in a web site project and I'm getting this error:

The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)

My project has a reference to System.DirectoryServices in web.config:

<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>  

And I do have using System.DirectoryServices in the files where I want to use it.

Does anybody have a clue where to look for the problem?

9条回答
Rolldiameter
2楼-- · 2019-03-14 10:17

On Solution Explorer right-click your project, then from the resulting menu, click on Add Reference, then under the .NET tab navigate to DirectoryServices.AccountManagement

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-03-14 10:21

This is a very old thread but just to provide a complete answer for the sake of posterity ;)

This issue occurs if the project is missing a reference to the .Net Component System.DirectoryServices

Adding this reference in the usual manner prefered by you will resolve the issue.

查看更多
何必那么认真
4楼-- · 2019-03-14 10:22

These problems occur when you are working with older .net version and trying to build with the latest IDE

It depends on which version of IDE you are using and also the current code version.

Check the web config,

In my case, I was using the Latest version i.e 4.7 and directoryService assembly are still referring to C#4.0.

Add below if you are using Latest version of id i.e 4.7

  <system.web>
  <location>

<compilation debug="false" numRecompilesBeforeAppRestart="100" targetFramework="4.7">
        <assemblies>
<add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
 </assemblies>
      </compilation>
</system.web>
  </location>
查看更多
登录 后发表回答