繁体   English   中英

错误CS0234:类型或名称空间名称'AccountManagement'在名称空间'System.DirectoryServices'中不存在

[英]error CS0234: The type or namespace name 'AccountManagement' does not exist in the namespace 'System.DirectoryServices'

我正在尝试为项目引用System.DirectoryServices.AccountManagement ,但始终收到此错误。 我已经去过VS 2017中的项目>添加引用,并包含System.DirectoryServices.AccountManagement.dll。 之后,我进入了解决方案资源管理器中的“引用属性”,并将“复制本地”属性设置为true。 这是来自csc的完整错误消息:

Microsoft (R) Visual C# Compiler version 2.8.3.63029 (e9a3a6c0)
Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(7,32): error CS0234: The type or namespace name 'AccountManagement' does not exist in the namespace 'System.DirectoryServices' (are you missing an assembly reference?)

这是更多信息:

using System;
using System.DirectoryServices; 
using System.DirectoryServices.AccountManagement; 
...
PrincipalContext context = new PrincipalContext(ContextType.Domain, "mycompany.local");
GroupPrincipal findAllGroups = new GroupPrincipal(context, "*");
PrincipalSearcher ps = new PrincipalSearcher(findAllGroups); 

您可能针对的是.Net Framework的旧版本。 转到“项目属性”,然后在“ Target framework下的“应用程序”选项卡中查找。 确保它是4或更高版本。

在此处输入图片说明

如果这不是问题,则执行“清理并重建”有时会解决此问题。

如果您想尝试某些事情,请尝试这种可能性。

创建两个虚拟的额外功能。 在代码中的某个地方调用第一个。

经过两遍编译(可能仍然会失败)。 在编辑器中编写一些代码,以强制“ Intellisense”从程序集中查找一些枚举值。

然后尝试再次编译。 (在黑暗中射击)。

一旦将其编译,就可以删除这两个函数。

这里是功能。

    private void CallThisToForceRefrence()
    {
        int x = 0;
        x = 1;
        x = (x + 1);
        if (x == 42)
        {
            DummyForRoslyn(); //will never execute
        }
        return;
    }

    private void DummyForRoslyn()
    {
        System.DirectoryServices.AccountManagement.PrincipalContext fakeCtx = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, "FakeNeverGoingToExecute");
        int sillyNum = 0;
        sillyNum = (int)fakeCtx.ContextType;
        if (sillyNum == (int)System.DirectoryServices.AccountManagement.ContextType.Domain)
        {
            // Does this Enum Refrence Force Roslyn to Go Looking in a First Refrence - First Compile Scenario ?
            sillyNum = 42;
        }
        return;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM