简体   繁体   English

C#-名称空间“ Windows”中不存在类型或名称空间名称“ Security”(您是否缺少程序集引用?)

[英]C# - The type or namespace name 'Security' does not exist in the namespace 'Windows' (are you missing an assembly reference?)

I'm trying to run this script but the IDE gives me the error mentioned in the title, specifically on line 6. I'm using Xamarin Studio 6.3 with .NET 4.5 as my target framework. 我正在尝试运行此脚本,但是IDE给了我标题中提到的错误,特别是在第6行。我将Xamarin Studio 6.3和.NET 4.5用作目标框架。 I chose a .NET Console Project as my solution for running this program. 我选择.NET控制台项目作为运行此程序的解决方案。 I've tried adding System.Security as an assembly reference, still received the error. 我尝试将System.Security添加为程序集引用,但仍然收到错误。 Then I added every .NET 4.5-related reference to my project just in case, issue persisted. 然后,我将每个与.NET 4.5相关的引用添加到我的项目中,以防万一,问题仍然存在。 Here is the script I'm trying to run: 这是我要运行的脚本:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Security.Credentials;

namespace PasswordVaultTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a handle to the Widnows Password vault
            Windows.Security.Credentials.PasswordVault vault = new PasswordVault();
            // Retrieve all the credentials from the vault
            IReadOnlyList<PasswordCredential> credentials = vault.RetrieveAll();
            // The list returned is an IReadOnlyList, so there is no enumerator.
            // No problem, we'll just see how many credentials there are and do it the
            // old fashioned way
            for (int i = 0; i < credentials.Count; i++)
            {
                // Obtain the credential
                PasswordCredential cred = credentials.ElementAt(i);
                // "Fill in the password" (I wish I knew more about what this was doing)
                cred.RetrievePassword();
                // Print the result
                Console.WriteLine(cred.Resource + ':' + cred.UserName + ':' + cred.Password);
            }
            Console.ReadKey();
        }
    }
}

The Reference you need to the Windows namespace is not visual by default. 默认情况下,您对Windows名称空间所需的引用不可见。 Per Alex's answer at the below post: Per Alex在以下帖子中的回答:

In the desktop projects the Core tab doesn't appear by default. 在桌面项目中,“核心”选项卡默认情况下不显示。 You can add the Windows Runtime by opening the shortcut menu for the project node, choosing Unload Project, adding the following snippet, and re-opening the project (on the project node choose Reload Project). 您可以通过打开项目节点的快捷菜单,选择“卸载项目”,添加以下代码片段,然后重新打开项目来添加Windows运行时(在项目节点上选择“重新加载项目”)。 When you invoke the Reference Manager dialog box, the Core tab appears. 调用“引用管理器”对话框时,将显示“核心”选项卡。

<PropertyGroup>
    <TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>

Make sure to check the Windows box on this tab. 确保选中此选项卡上的Windows框。 You should then be able to use WinRT elements. 然后,您应该能够使用WinRT元素。

I have done this and your code statement above compiles without error. 我已经做到了,上面的代码语句可以正确编译。 Here is a link to the original answer: 这是原始答案的链接:

How to access the stored credentials (Password Value?) 如何访问存储的凭据(密码值?)

暂无
暂无

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

相关问题 CS0234 C#类型或名称空间名称&#39;Slydeextender&#39;在名称空间中不存在(您是否缺少程序集引用?) - CS0234 C# The type or namespace name 'Slydeextender' does not exist in the namespace (are you missing an assembly reference?) C#类型或名称空间名称“ Interop”在名称空间“ Microsoft.Office”中不存在(您是否缺少程序集引用?) - C# The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?) 类型或名称空间名称在名称空间中不存在“是否缺少程序集引用?” - The type or namespace name does not exist in the namespace ''are you missing an assembly reference ?" 命名空间中不存在类型或命名空间名称(您是否缺少程序集引用?) - The type or namespace name does not exist in the namespace (are you missing an assembly reference?) 类型或名称空间名称“ OpenIdConnect”在名称空间“ Microsoft.Owin.Security”中不存在(您是否缺少程序集引用?) - The type or namespace name 'OpenIdConnect' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?) 如何解决错误:名称空间“ Windows”中不存在类型或名称空间名称“ Phone”(您是否缺少程序集引用?)? - How to solve error: The type or namespace name 'Phone' does not exist in the namespace 'Windows' (are you missing an assembly reference?)? WPF类型或名称空间名称“浏览器”在名称空间“ System.Windows”中不存在(您是否缺少程序集引用?) - WPF The type or namespace name 'Browser' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) VS 2017 c#错误CS0234命名空间中不存在类型或命名空间名称(您是否缺少程序集引用?) - VS 2017 c# Error CS0234 The type or namespace name does not exist in the namespace (are you missing an assembly reference?) 名称空间“系统”中不存在类型或命名空间名称“事务”(您是否缺少程序集引用?) - C#ASP.NET - The type or namespace name 'Transactions' does not exist in the namespace 'System' (are you missing an assembly reference?) - C# ASP.NET 错误CS0234:类型或名称空间名称&#39;OAuth&#39;在名称空间&#39;Microsoft.Owin.Security&#39;中不存在(您是否缺少程序集引用?) - error CS0234: The type or namespace name 'OAuth' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM