Has anyone experienced with the below unit test execution error both in Visual Studio IDE 2019 (16.9.3) and command line through vstest.console.exe (16.9.1)?
This happens even after installing the latest .NET 5.0.5 (5.0.202 SDK) following this only related post.
I even tried to debug into the Newtonsoft 13.0.1 but only to find the constructor just quits and throws the exception here. It does not even hit the JContainer ctor here.
The same logic runs fine during runtime but does not through/within a test [Fact] function. I extracted it out to make sure it is isolated and does not go through any mock/fakes. Seems like something with the .NET test engine somewhere?
The failing unit test project is using the following:
- xunit (2.4.1)
- xunit.runner.visualstudio (2.4.3)
- NSubstitute (4.2.2)
- mstest.testframework (2.2.3)
- Mircrosoft.NET.Test.Sdk (16.9.4)
- Microsoft.QualityTools.Testing.Fakes (16.7.4-beta.20330.2)
It is a .NET FW 4.6.2 targeting project with csproj file setup with .NET SDK style instead of the old .NET FW structure.
Stack trace from the unit test command line execution:
Error Message:
System.InvalidProgramException : Common Language Runtime detected an invalid program.
Stack Trace:
at Newtonsoft.Json.Linq.JContainer..ctor(JContainer other)
at Newtonsoft.Json.Linq.JObject..ctor(JObject other)
at Newtonsoft.Json.Linq.JObject.CloneToken()
at Newtonsoft.Json.Linq.JContainer.EnsureParentToken(JToken item, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JContainer.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JContainer.TryAddInternal(Int32 index, Object content, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JContainer.Add(Object content)
at Newtonsoft.Json.Linq.JArray.Add(JToken item)
at at MyUnitTests.<MyTest_HasNeededData_ReturnsData>d__45.MoveNext() in XXXXXXXXXXXXXXXXXXXXXXX:line 643
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Please help!!! Thanks in advance.