相关疑难解决方法(0)

为什么WindowsIdentity类在.NET Core中不可见

在VisualStudio 2017 .NET Core 2.0控制台应用程序中具有以下代码

using System;
using System.Security.Principal;

namespace smallTests
{
    class Program
    {
        static void Main(string[] args)
        {
            var identity = WindowsIdentity.GetCurrent();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么我收到错误:

The name 'WindowsIdentity' does not exist in the current context    
Run Code Online (Sandbox Code Playgroud)

如果我可以在.Net Core docs中的.NET Core 2.0库中看到这个类?

相同的代码适用于.NET控制台应用.

[编辑]

@Will @JohnnyL评论说我没有提及System.Security.Principal.Windows.dll,这是真的.

但我很好奇为什么它不起作用,因为在.NET 4.6.1项目中(类WindowsIdentity可见)我也没有System.Security.Principal.Windows.dll具体提到这一点.但是我引用了System.dll.

我一直认为它像命名空间层次结构一样工作.例如,当我提到

System.Security.Principal.dll

我可以使用里面的课程

System.Security.Principal.Windows.dll.

我错了吗?

System.Security.Principal.dll手动添加到.NetCore解决方案但它仍然无效.

[EDIT2]

@Will非常感谢你们很多关于它帮助我的主题.我试图弄明白是WindowsIdentity与Core兼容,看来请注意:

在声明区域的这个apisof.net中,我可以看到WindowsIdentity在,.Net Core 2.0 System.Security.Principal.Windows, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a 但我没有System.Security.Principal.Windows.dll引用,我应该添加吗?如果是的话从哪里来? …

.net c# .net-core

9
推荐指数
1
解决办法
6344
查看次数

标签 统计

.net ×1

.net-core ×1

c# ×1