且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Visual Studio 2017在单元测试期间崩溃

更新时间:2023-02-14 17:36:33

这只发生在VS2017上吗? 还是VS2015?


你介意分享导致此错误的代码示例吗?


您可以尝试在测试中设置断点  ;脚本 调试它并找出哪一行 抛出异常。


根据错误消息, NullReferenceException 始终表示:您正在尝试使用引用,并且未初始化引用(或它曾被初始化,但不再初始化)。这意味着引用为null,而
则无法通过空引用访问成员(例如方法)。



 


问候,


Fletcher


I am moving from 2015 to 2017 and running established unit tests. 2017 is crashing:

[4/2/2018 3:55:30 PM Error] System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.TestWindow.Model.Observable.OnPropertyChanged(String info)
   at Microsoft.VisualStudio.TestWindow.Model.Test.UpdateDataHasVisibleChange(TestData newTestData, Int32 index)
   at Microsoft.VisualStudio.TestWindow.Model.VirtualTestCollection.CreateTest(Int32 index, TestData testData, Dictionary`2 knownTests)
   at Microsoft.VisualStudio.TestWindow.Model.VirtualTestCollection.RefreshTests(List`1& items)
   at Microsoft.VisualStudio.TestWindow.Model.VirtualTestCollection.Refresh()
   at Microsoft.VisualStudio.TestWindow.Model.TestGroup.Refresh(CancellationToken token)
   at Microsoft.VisualStudio.TestWindow.Model.TestGroupCollection.<RefreshCollection>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Model.TestGroupCollection.<>c__DisplayClass51_0.<<ProcessChange>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Model.TestGroupCollection.<AwaitChangeComplete>d__50.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Model.VirtualReadOnlyTestDataStore.<ProcessChange>d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Model.VirtualReadOnlyTestDataStore.<ProcessChange>d__56.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Model.VirtualReadOnlyTestDataStore.<>c__DisplayClass55_0.<<OnUnitTestChanged>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Extensibility.ILoggerExtensions.<CallWithCatchAsync>d__4`1.MoveNext()

If I close VS and reopen the solution the unit tests will run.

Also unit tests that pass in Release mode are failing in Debug mode. When I debug the test, they fail in a different location and the shim function does not appear to be called.

Does this only happen to VS2017?  Or VS2015 as well?

Would you mind share a code sample that cause this error?

You could try to put a breakpoint in your test script to debug it and find out which line throw the exception.

Based on the error message, NullReferenceException always means: you are trying to use a reference, and the reference is not initialized (or it was once initialized, but is no longer initialized). This means the reference is null, and you cannot access members (such as methods) through a null reference.

 

Regards,

Fletcher