C# System.DirectoryServices 在命名空间“System”中未被识别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/265096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.DirectoryServices is not recognised in the namespace 'System'
提问by jansokoly
I'm trying to use System.DirectoryServices
in a web site project and I'm getting this error:
我正在尝试System.DirectoryServices
在网站项目中使用,但出现此错误:
The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)
命名空间“System”中不存在类型或命名空间名称“DirectoryServices”(您是否缺少程序集引用?)
My project has a reference to System.DirectoryServices
in web.config
:
我的项目引用了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.
我确实using System.DirectoryServices
在我想使用它的文件中。
Does anybody have a clue where to look for the problem?
有没有人知道在哪里寻找问题?
采纳答案by Marc Gravell
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.
Web 服务器(IIS 或其他)是否配置为将文件夹作为应用程序运行(即显示为齿轮),并且它是否使用了正确版本的 ASP.NET?如果它作为 1.1 运行,它的一部分可能会起作用 - 但它无法在 1.1 GAC 中找到 2.0 程序集。
回答by Marc Gravell
Is this a web siteproject, or a web applicationproject. With the latter, references are handled via the .csproj - i.e. via the "References" node in Solution Explorer.
这是一个网站项目,还是一个网络应用项目。对于后者,引用通过 .csproj 处理 - 即通过解决方案资源管理器中的“引用”节点。
回答by Mitch Wheat
Shot in the dark: have you tried adding to the web.config:
在黑暗中拍摄:您是否尝试添加到 web.config:
<compilation debug="true">
<assemblies>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
回答by Salman Siddiqui
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
如果项目缺少对 .Net 组件System.DirectoryServices的引用,则会出现此问题
Adding this reference in the usual manner prefered by you will resolve the issue.
以您喜欢的通常方式添加此引用将解决该问题。
回答by user1947015
- Right click on References under your solution.
- Select Add Reference. The reference can be found under the Framework Assemblies list. Select System.DirectoryServicesand click Add.
- 右键单击解决方案下的引用。
- 选择添加引用。参考可以在框架组件列表下找到。选择System.DirectoryServices并单击添加。
回答by user2148239
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
在解决方案资源管理器上右键单击您的项目,然后从结果菜单中单击添加引用,然后在 .NET 选项卡下导航到 DirectoryServices.AccountManagement
回答by Navid Golforoushan
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.
当我尝试将网站转换为网络应用程序时,我遇到了同样的问题。看起来 vs 未能加载程序集应该与版本控制有关。切换到web.config
并向其添加程序集,如下所示。确保 DLL 版本与您的应用程序目标 .NET 版本匹配。
<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
要获得公钥,您需要启动Developer Command Prompt for VS
. 更改为上述 ex 上的 GAC 目录相关框架C:\Windows\Microsoft.NET\Framework\v4.0.30319
并调用
sn -T System.DirectoryServices.dll
回答by BasmaSH
I think you should install Directory Services Package.
我认为您应该安装 Directory Services Package。
Install-Package System.DirectoryServices -Version 4.0.0
回答by Pratheek S
These problems occur when you are working with older .net version and trying to build with the latest IDE
当您使用较旧的 .net 版本并尝试使用最新的 IDE 进行构建时会出现这些问题
It depends on which version of IDE you are using and also the current code version.
这取决于您使用的 IDE 版本以及当前的代码版本。
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.
就我而言,我使用的是最新版本,即 4.7 和directoryService
程序集仍然指的是 C#4.0。
Add below if you are using Latest version of id i.e 4.7
如果您使用的是最新版本的 id ie 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>