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条回答
\"骚年 ilove
2楼-- · 2019-03-14 09:57
  1. Right click on References under your solution.
  2. Select Add Reference. The reference can be found under the Framework Assemblies list. Select System.DirectoryServices and click Add.
查看更多
Anthone
3楼-- · 2019-03-14 10:00

Is the web-server (IIS or whatever) configured to run the folder as an application (i.e. shows as a cog), and is it using the correct version of ASP.NET? If it is running as 1.1, bits of it might work - but it would fail to find that 2.0 assembly in the 1.1 GAC.

查看更多
叛逆
4楼-- · 2019-03-14 10:05

I think you should install Directory Services Package.

Install-Package System.DirectoryServices -Version 4.0.0 

Directory Services Package

查看更多
小情绪 Triste *
5楼-- · 2019-03-14 10:09

I had the same problem when I tried to convert website to web-app. It looks like vs failing to load the assembly should be related to versioning. switch to web.config and add the assembly to it as bellow. make sure the DLL version is matching your application targeted .NET version.

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>

for getting a public key you need to launch Developer Command Prompt for VS. Change to GAC directory related framework on above ex C:\Windows\Microsoft.NET\Framework\v4.0.30319 and call

sn -T System.DirectoryServices.dll
查看更多
狗以群分
6楼-- · 2019-03-14 10:12

Is this a web site project, or a web application project. With the latter, references are handled via the .csproj - i.e. via the "References" node in Solution Explorer.

查看更多
Fickle 薄情
7楼-- · 2019-03-14 10:15

Shot in the dark: have you tried adding to the web.config:

<compilation debug="true">
     <assemblies>
          <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
     </assemblies>
</compilation>
查看更多
登录 后发表回答