加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

.net – System.Security.Cryptography.X509Certificates.X509Ce

发布时间:2020-12-14 04:22:52 所属栏目:Windows 来源:网络整理
导读:我安装了VS2015 RTM和VS2013 Update 5 RTM.现在我的解决方案没有构建,因为我的接口具有返回类型X509Certificate2.现在我的假货不是建造的.我还创建了一个测试项目,我遇到了同样的问题,所以这不是我的解决方案.我收到的消息是: Cannot generate stub for Cla
我安装了VS2015 RTM和VS2013 Update 5 RTM.现在我的解决方案没有构建,因为我的接口具有返回类型X509Certificate2.现在我的假货不是建造的.我还创建了一个测试项目,我遇到了同样的问题,所以这不是我的解决方案.我收到的消息是:

Cannot generate stub for ClassLibrary1.Interfaces.ICertificateProvider: method System.Security.Cryptography.X509Certificates.X509Certificate2 ClassLibrary1.Interfaces.ICertificateProvider.getbla() unstubbable: method is abstract and could not be stubbed,type System.Security.Cryptography.X509Certificates.X509Certificate2 is not available in the target framework version.

现在我卸载了VS2015 RTM,但问题仍然存在.当我用返回类型注释掉该方法时,证书一切正常.当我取消注释时,问题出在那里.

更新1
我刚在另一个系统上测试了这个.首先,我尝试使用VS2013 Update 4和VS2015 RC.有了这个设置一切都很好.然后我在该系统上安装了Update 5 RTM,然后它不再工作了.所以Update 5一定是问题所在!
结束更新

重现:
使用.Net Framework 4.5.1创建包含2个类库和1个测试项目的解决方案.
在类库1中创建一个接口.

namespace ClassLibrary1.Interfaces
{
    public interface ICertificateProvider
    {
        // Comment this line so you can build your fakes assembly...
        X509Certificate2 getbla();
    }
}

在第二个类库中创建一个类.实现接口并添加对第一个类库的引用.

namespace ClassLibrary1
{
    public class CertificateProvider :   ClassLibrary1.Interfaces.ICertificateProvider
    {
        public X509Certificate2 getbla()
        {
            throw new NotImplementedException();
        }
    }
}

为unittest项目中的接口项目添加fakes程序集.在测试中通过以下代码:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ClassLibrary1.Interfaces.Fakes;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            StubICertificateProvider provider = new StubICertificateProvider();
        }
    }
}

现在您的项目将无法构建.如果您在项目将构建的界面中注释该方法.
在.fakes文件中启用诊断以获取错误消息.

谁有解决方案?

更新2
更改使用.Net Framework 4.6的解决方案.更改为4.5.2不起作用.

更新3
链接到Github的官方错误:
https://github.com/dotnet/coreclr/issues/1303

我刚刚将测试项目更新到.NET 4.6,它运行良好.在那之后我有几个内部类,这些假货是不可见的,所以使用

[assembly:InternalsVisibleT

在AssemblyConfig.cs中最好让它最终运行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读