SpecFlow Jenkins Run Failing looking for NewtonSoft v9.0.0.0 - specflow

I am setting up a new project on Jenkins and I am having a slight issue. The build is successful but when specrun begins, all tests are ignored and it is throwing the below error.
TechTalk.SpecRun.Framework.SpecRunException: At least one test thread aborted. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
My App.config I have added the below to support the new version:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
I still throw the error. I have uninstalled, re-installed and searched for 9.0.0.0 but nothing. I have 9.0.0.1 in private assemplies as well as an old v6. There are similar posts out there on StackOverflow and other sites but I have not been able to get this to work. I have also tried executing from command line. Any suggestions?
SpecFlow v1.78
MSBuild v3.78
SpecRun.Runner v3.1.44
SpecRun.SpecFlow.3-1-0 v3.144
There was a bug in upgrading to current so I had to rollback.

Related

Why does MassTransit.Serialization.SystemTextJsonMessageSerializer 8.0.3 thrown an exception when configuring the bus in .NET 4.6.2 + ASP .NET MVC

We have a .NET Framework 4.6.2 ASP .NET MVC application that configures MassTransit.RabbitMQ 8.0.3 in the Startup class
The code is below
var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.UseNewtonsoftJsonSerializer(); //Also tried UseNewtonsoftRawJsonSerializer and without
cfg.Host(WebConfigurationManager.AppSettings["RabbitMQHost"], "/", h =>
{
h.Username(WebConfigurationManager.AppSettings["RabbitMQUsername"]);
h.Password(WebConfigurationManager.AppSettings["RabbitMQPassword"]);
});
});
This is the exception
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'MassTransit.Serialization.SystemTextJsonMessageSerializer' threw an exception.
Source=MassTransit
StackTrace:
at MassTransit.Configuration.SystemTextJsonMessageSerializerFactory.get_ContentType()
at MassTransit.Configuration.SerializationConfiguration.AddSerializer(ISerializerFactory factory, Boolean isSerializer)
at MassTransit.Configuration.SerializationConfiguration.AddSystemTextJson()
at MassTransit.Configuration.EndpointConfiguration..ctor(ITopologyConfiguration topology)
at MassTransit.RabbitMqTransport.Configuration.RabbitMqBusConfiguration..ctor(IRabbitMqTopologyConfiguration topologyConfiguration)
at MassTransit.RabbitMqBusFactory.Create(Action`1 configure)
at Startup.ConfigureMassTransit(IUnityContainer unityContainer) in C:\p\Startup.cs:line 79
at Startup.Configuration(IAppBuilder app) in C:\p\Startup.cs:line 59
Inner Exception 1:
TypeInitializationException: The type initializer for 'System.Text.Encodings.Web.DefaultJavaScriptEncoder' threw an exception.
Inner Exception 2:
TypeInitializationException: The type initializer for 'PerTypeValues`1' threw an exception.
Inner Exception 3:
FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Inner Exception 4:
FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What I've tried
I read the Serialization section of the MassTransit 8 upgrade guide. I added UseNewtonsoftJsonSerializer. Same error.
I had a look at Microsoft's Migration guide from NewtonSoft.Json to System.Text.Json. Our web app includes both System.Text.Json and NewtonSoft.Json. I tried uninstall System.Text.Json but Masstransit requires that. We use NewtonSoft.Json in a lot of places in our code.
I found some assembly redirects in the .config files. I removed those but I still get the error.
Checked that System.Runtime.CompilerServices.Unsafe (6.0) is installed (as a nuget package)
Questions
Why am I getting this error and how to I fix it?
Other details
One of the errors mentions "DefaultJavaScriptEncoder" and another mentions "SystemTextJsonMessageSerializer".
The Webapp uses Unity 5.6.0 (and Unity.Abstractions 3.2.0, Unity.Container 5.6.0, Unity.MVC 5.0.12, Unity.WebAPI 5.3.0)
Using MassTransit 7.1.8 we do not have these problems.
Update 1
Not adding this as an answer because it's specific to my system.
I managed to fix this by adjusting / fiddling with the dependenyAssembly / bindingRedirect in the web.config file.
I remove System.Runtime.CompilerServices.Unsafe dependencyAssembly / bindingRedirect.
I added these dependencyAssembly / bindingRedirect (which I got from the exception message: change dependencyAssembly, run program, get exception, repeat)
Microsoft.Extensions.Logging.Abstractions
System.Diagnostics.DiagnosticSource
Microsoft.Bcl.AsyncInterfaces
System.Threading.Channels
<!--<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>-->
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.18.0" newVersion="3.1.18.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>

Newtonsoft.Json, Difference in file version and reference version

I was trying to do a binding redirect for an older version of Newtonsoft.Json to the latest version and kept on failing. Eventually updated to a range from 0.0.0.0 - 9.0.0.0 -> 9.0.0.0 and it worked.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="0000000" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
But when I first initially started, I looked up the file version via file properties and added the version number 9.0.1.19813 and kept getting an error stating that the assembly could not be found. I could not find a reason why it could not find it until I looked up the version number via properties under references and the file version was 9.0.0.0
Any reason why the file version in file properties and the version shown in reference properties would be different and causing reference issues?
Also, to confirm I used ildasm.exe and it shows ver 9.0.0.0. I am a bit confused.
any comments would be helpful.
Regards
Found an explanation at Microsoft docs.
https://support.microsoft.com/en-nz/help/556041

Cannot load System.Web.Mvc on TeamCity when running MSTest

I'm converting a working Visual Studio 2015 build on TeamCity to Visual Studio 2017, and I'm having an issue when running MSTest. I'm getting the following error message:
System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I searched the entire solution and couldn't find anything explicitly referencing System.Web.Mvc v3.0.0.1. I attempted to add the following assembly redirect in the app.config of the Test project to fix the problem:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
However, the problem still persists. After debugging, I discovered the error only occurs in code using System.Web.Mvc.UrlHelper. When I comment that code the build works correctly.
The code compiles and tests run correctly when running locally from Visual Studio.
Here's a screenshot of the solution build step in TeamCity:
And a screenshot of the MSTest build step in TeamCity:

TFS Build 2012, ASP.NET MVC & MSB3247: Found conflicts between different versions of same dependent assembly

I'm getting the MS Build warning "MSB3247: Found conflicts between different versions of the same dependent assembly." when building the a web project (ASP.NET MVC4) under TFS Build 2012.
Consider app.config remapping of assembly "System.Web.Mvc, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "2.0.0.0" [] to Version "4.0.0.0" [XXXX\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll] to solve conflict and get rid of warning.
Consider app.config remapping of assembly "WebGrease, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "1.3.0.0" [] to Version "1.5.2.14234" [XXXX\packages\WebGrease.1.5.2\lib\WebGrease.dll] to solve conflict and get rid of warning.
Consider app.config remapping of assembly "Antlr3.Runtime, Culture=neutral, PublicKeyToken=eb42632606e9261f" from Version "3.4.1.9004" [] to Version "3.5.0.2" [XXXX\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll] to solve conflict and get rid of warning.
I know which references are causing these and that's not the problem. I have the relevant binding redirects in place in the web.config file, most of which are set by NuGet when referencing the relevant package(s).
Problem is this is a web project, and it is as if MSBuild is ignoring the binding redirects in the web.config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
This warning does occur in the local developer build, but not consistently every time.
The interesting thing is that if I add an app.config file to the web project and place the assembly redirects in there (still keeping the original redirects in the web.config file) the warning goes away, both locally and with TFS Build (where it happens consistently.).
WTF? Any ideas?
I have finally managed to isolate the root cause of this error and identify a few red-herrings.
First, it is a red herring that the issue does not occur where Visual Studio 2012 installed or does not happen on the developer workstations. While the issue occurs consistently on the build servers (TFS Build), it happens on the workstations too, provided the steps "Batch Clean All", followed "Build" are followed.
Second, I can now confirm that the culprit for the MSB 3247 warning is the Microsoft BCL Build Nuget Package:
Microsoft.Bcl.Build.1.0.10
It modifies the web application project file, adding the following Import:
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
If I comment it out of the project file, the issue on the local workstations and the TFS Build Servers goes away.
Unfortunately I do not know what the impact of commenting out the above really means. Can I leave it commented out - what will happen?
The reason this Microsoft.Bcl.Build NuGet package is part of the project is because it's marked as a dependency to the Microsoft.Net.Http NuGet package which we do use. Earlier versions of the Microsoft.Net.Http NuGet package did not have this dependency on Microsoft.Bcl and Microsoft.Bcl.Build packages.
Hope this helps someone.
PS: This has a corresponding, but so far unhelpful forum post here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/faa1b607-50bb-48e3-bd5d-76f4fc02ad4c/ms-build-gives-warning-msb3247-found-conflicts-between-different-versions-of-same-dependent?forum=msbuild
I don't have the Bcl.Build stuff anywhere that I can see, and this is the exact error I'm getting on my 2013 TFS build server.
My warnings look like this:
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets (1635): Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file:
Which, I already had in my web.config, minus the culture= param, in both my web and api projects.
I'm sorry I don't have any answer for you, I've just gotten my first build to complete, and these are the last two warnings I'm getting.

NuGet adding rogue line to web.config MVC4

Every time I install ANYTHING using Nuget, this gets added to my <Runtime><asseblyBinding> section in my web.config:
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Obviously I'm using MVC4 so references to Razor 2.0.0.0 breaks things, and the following runtime error is thrown.
Could not load type 'System.Web.Razor.Parser.SyntaxTree.CodeSpan' from assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Its easy to fix, just remove the rouge section from Web.Config, but very annoying all the same! Anyone know why this might be happening, or how to fix this?
I'm using Nuget Package Manager Version 1.7.30402.9028
Individual packages are able to provide installation routines written in PowerShell, which is probably what's happening here. Does the same thing happen even if you install something unrelated to Razor, like, say, JQuery?
Thanks,
Clay

Resources