![](/img/trans.png)
[英]Error CS0234: The type or namespace name 'CustomMarshalers' does not exist in the namespace 'System.Runtime.InteropServices'
[英]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);
如果您想嘗試某些事情,請嘗試這種可能性。
創建兩個虛擬的額外功能。 在代碼中的某個地方調用第一個。
經過兩遍編譯(可能仍然會失敗)。 在編輯器中編寫一些代碼,以強制“ 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.