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

问题描述 投票:0回答:1

我正在尝试运行此脚本,但IDE给出了标题中提到的错误,特别是在第6行。我使用Xamarin Studio 6.3和.NET 4.5作为我的目标框架。我选择了一个.NET Console Project作为运行该程序的解决方案。我已经尝试将System.Security添加为程序集引用,仍然收到错误。然后我将每个与.NET 4.5相关的引用添加到我的项目中以防万一,问题仍然存在。这是我正在尝试运行的脚本:

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();
        }
    }
}
c# .net xamarin-studio
1个回答
1
投票

默认情况下,Windows命名空间所需的引用不可视。 Per Alex在以下帖子中回答:

在桌面项目中,默认情况下不显示Core选项卡。您可以通过打开项目节点的快捷菜单,选择卸载项目,添加以下代码段并重新打开项目(在项目节点上选择“重新加载项目”)来添加Windows运行时。调用“参考管理器”对话框时,将显示“核心”选项卡。

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

确保选中此选项卡上的Windows框。然后,您应该能够使用WinRT元素。

我已经完成了这个,你上面的代码语句编译没有错误。这是原始答案的链接:

How to access the stored credentials (Password Value?)

© www.soinside.com 2019 - 2024. All rights reserved.