I installed VS2015 RTM en VS2013 Update 5 RTM. Now my solution is not building because I have an interface that has as returntype a X509Certificate2
. Now my fakes aren't build. I also created a test project and there I have the same problem so it isn't my solution. The message that I get is:
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.
Now I uninstalled VS2015 RTM but the problem is still there. When I comment out the the method with as return type the certificate everything works. When I uncomment it, the problem is there.
Update 1 I just tested this on another system. First I tried it with VS2013 Update 4 en VS2015 RC. With that setup everything was fine. I then installed Update 5 RTM on that system and then it didn't work anymore. So Update 5 must be the problem! End update
To reproduce: Create a solution with 2 class libraries and 1 test project with .Net Framework 4.5.1. Create an interface in class library 1.
namespace ClassLibrary1.Interfaces
{
public interface ICertificateProvider
{
// Comment this line so you can build your fakes assembly...
X509Certificate2 getbla();
}
}
Create a class in the second class library. Implement the interface and add a reference to the first class library.
namespace ClassLibrary1
{
public class CertificateProvider : ClassLibrary1.Interfaces.ICertificateProvider
{
public X509Certificate2 getbla()
{
throw new NotImplementedException();
}
}
}
Add a fakes assembly for the interface project in the unittest project. Past the following code in a test:
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();
}
}
}
Now your project won't build. If you comment the method in the interface your project will build.
Enable the diagnostics in your .fakes
file for the error message.
Anyone a solution?
Update 2 Changing the solution to use .Net Framework 4.6 works. Changing to 4.5.2 doesn't work.
Update 3 Link to official bug of Github: https://github.com/dotnet/coreclr/issues/1303