System.Security.Cryptography.X509Certificates.X509Certificate2在目标框架版本中不可用

Ral*_*sen 7 .net system mscorlib microsoft-fakes visual-studio-2013

我安装了VS2015 RTM和VS2013 Update 5 RTM.现在我的解决方案没有构建,因为我有一个具有返回类型a的接口X509Certificate2.现在我的假货不是建造的.我还创建了一个测试项目,我遇到了同样的问题,所以这不是我的解决方案.我收到的消息是:

无法为ClassLibrary1.Interfaces.ICertificateProvider生成存根:方法System.Security.Cryptography.X509Certificates.X509Certificate2 ClassLibrary1.Interfaces.ICertificateProvider.getbla()unstubbable:方法是抽象的,无法存根,键入System.Security.Cryptography.X509Certificates.X509Certificate2在目标框架版本中不可用.

现在我卸载了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();
    }
}
Run Code Online (Sandbox Code Playgroud)

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

namespace ClassLibrary1
{
    public class CertificateProvider :   ClassLibrary1.Interfaces.ICertificateProvider
    {
        public X509Certificate2 getbla()
        {
            throw new NotImplementedException();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

谁有解决方案?

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

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

dei*_*i79 0

我刚刚将测试项目更新到 .NET 4.6,效果很好。之后我有几个内部类,这些类对于假货来说是不可见的,所以使用

[装配:InternalsVisibleT

在 AssemblyConfig.cs 中也是一个让它最终运行的好主意。