I've installed Visual Studio 2015 as a try-out and since then my unit tests that use fakes won't compile anymore, not even on VS 2013. The unit test project targets .net 4.5.
Msdn suggest changing the target framework version. The error is gone if I change the targeted framework to 4.6 but I cannot update my project to .net 4.6 as every developer must update at once.
Error that I get:
The primary reference "mscorlib.4.0.0.0.Fakes" could not be resolved because it was built against the ".NETFramework,Version=4.6 fraemwork. This is a higher version than the currently targeted framework ".NETFramework,Version=4.5".
I've also tried to remove the fakes and recreate them but they do not build, I get errors like this:
The type or namespace name 'EventDataAttribute' does not exist in the namespace 'System.Diagnostics.Tracing'*;
Any fixes for this?
You can probably remove the problem classes. If your build output has statements like
warning CS0115: 'System.Security.Cryptography.X509Certificates.Fakes.StubX509Certificate2.Dispose(bool)': no suitable method found to override
warning CS0234: The type or namespace name 'EventDataAttribute' does not exist in the namespace 'System.Diagnostics.Tracing'
Then it can be removed from mscorlib.fakes or System.fakes files
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="mscorlib" Version="4.0.0.0"/>
<StubGeneration>
<Remove FullName="System.Diagnostics.Tracing"/>
<Remove FullName="System.Text.Encoding"/>
<Remove FullName="System.Security.Cryptography" />
</StubGeneration>
</Fakes>
Now, it may be a bit more nuanced than that. In order to get it to work, I needed to target the Unit Test project to 4.6 to generate the mscorlib.4.0.0.0.Fakes .dll the first time. Then I could retarget it back down to 4.5.1. But, working with the config may be worth a bit of your time as I was able to work around a similar problem.
Here's a Microsoft problem report which is where I got the workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With