【问题标题】:System.IO.FileNotFoundException been thrown when calling method in PCL in Windows phone 8在 Windows phone 8 中调用 PCL 中的方法时引发 System.IO.FileNotFoundException
【发布时间】:2014-07-04 06:25:48
【问题描述】:

我正在为 Windows Phone 8 项目的 PCL 中的字符串解密(从数据库中读取)。下面是场景:

一个包含 3 个项目的解决方案,Windows phone UIwindows phone 便携类库类库

类库项目有一个类 StringDecryption,其中包含以下代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace DecryptString
{
    public class StringDecryption
    {
        public string Decryption(string encryptedTExt)
        {
            var protectedText = this.ReadEncryptedData(encryptedTExt);

            // Decrypt the text by using the Unprotect method.
            var textByte = ProtectedData.Unprotect(protectedText, null, DataProtectionScope.CurrentUser);

            // Convert the text from byte to string and display it in the text box.
            return Encoding.UTF8.GetString(textByte, 0, textByte.Length);

        }

        public byte[] ReadEncryptedData(string text)
        {
            var reader = new StreamReader(text).BaseStream;
            var textArray = new byte[reader.Length];

            reader.Read(textArray, 0, textArray.Length);
            reader.Close();

            return textArray;
        }

        public string Getname()
        {
            return "MyName";
        }
    }
}

我将这个类库中的 dll 引用到可移植类库中,当从这个库调用 Decryption 方法时,它抛出 System.IO.FileNotFoundException 但是当我调用 时同样运行良好>Getname 方法。来自异常的完整消息是无法加载文件或程序集 'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一。系统找不到指定的文件。

有什么方法可以解决这个问题,或者有什么其他方法可以加密或解密 PCL 中的字符串吗??

提前致谢。

【问题讨论】:

    标签: c# c#-4.0 windows-phone-8 portable-class-library class-library


    【解决方案1】:

    听起来您正在从“可移植类库”引用“类库”。这不受支持 - 类库仅支持一个平台(可能是完整的 .NET Framework),因此它不会在您的可移植类库目标的其他平台上运行。

    有没有办法解决这个问题或任何其他方式来加密或 在 PCL 中解密一个字符串??

    我建议查看 PCL Crypto 库。

    有关我认为对您有帮助的更多一般信息,请参阅我的博文:How to Make Portable Class Libraries Work for You

    【讨论】:

    • 类库中的其中一个方法(Getname)被成功调用,而其他方法则没有。似乎这是受支持的,并且还有其他一些我必须弄清楚的问题。我想尝试 PCL Crypto,但我没有得到太多关于这方面的信息。您能否提供更多有关如何使用 PCL 加密库的信息?
    • @PraveshPesswani 不支持。您只是幸运地使用了 Getname 方法,因为它很简单并且不调用任何其他 API。 PCL Crypto 是一个开源项目。我将您链接到 NuGet 包页面,如果您单击“项目站点”链接,它将带您到项目页面:pclcrypto.codeplex.com 如果您需要更多帮助,我建议在 StackOverflow 上发布另一个问题并可能 ping Andrew Arnott (作者)在 Twitter 上向他指出这个问题。
    猜你喜欢
    • 2014-08-26
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多