System.DirectoryServices is not recognised in the namespace 'System'

后端 未结 9 1318
一整个雨季
一整个雨季 2021-02-05 02:23

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

The type or namespace name \'DirectoryServices

相关标签:
9条回答
  • 2021-02-05 02:42
    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.
    0 讨论(0)
  • 2021-02-05 02:44

    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
    
    0 讨论(0)
  • 2021-02-05 02:56

    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>
    
    0 讨论(0)
  • 2021-02-05 02:56

    I think you should install Directory Services Package.

    Install-Package System.DirectoryServices -Version 4.0.0 
    

    Directory Services Package

    0 讨论(0)
  • 2021-02-05 02:58

    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.

    0 讨论(0)
  • 2021-02-05 02:59

    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.

    0 讨论(0)
提交回复
热议问题