Visual Studio 2017在单元测试期间崩溃 [英] Visual Studio 2017 crashing during unit testing

查看:142
本文介绍了Visual Studio 2017在单元测试期间崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从2015年到2017年并开始运行既定的单元测试。 2017年崩溃:


[4/2/2018 3:55:30 PM错误] System.NullReferenceException:对象引用未设置为对象的实例。

  在Microsoft.VisualStudio.TestWindow.Model.Observable.OnPropertyChanged(字符串信息)

  在Microsoft.VisualStudio.TestWindow.Model.Test.UpdateDataHasVisibleChange(TestData newTestData,Int32 index)

  在Microsoft.VisualStudio.TestWindow.Model.VirtualTestCollection.CreateTest(Int32索引,TestData testData,Dictionary`2 knownTests)

  在Microsoft.VisualStudio.TestWindow.Model.VirtualTestCollection.RefreshTests(List`1& items)

  在Microsoft.VisualStudio.TestWindow.Model.VirtualTestCollection.Refresh()

  在Microsoft.VisualStudio.TestWindow.Model.TestGroup.Refresh(CancellationToken令牌)

  在Microsoft.VisualStudio.TestWindow.Model.TestGroupCollection。< RefreshCollection> d__41.MoveNext()

---从抛出异常的上一个位置开始的堆栈跟踪结束---

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在Microsoft.VisualStudio.TestWindow.Model.TestGroupCollection。<> c__DisplayClass51_0。<<< ProcessChange> b__0> d.MoveNext()

---来自先前位置的堆栈跟踪结束被扔了---

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在Microsoft.VisualStudio.TestWindow.Model.TestGroupCollection。< AwaitChangeComplete> d__50.MoveNext()

---从抛出异常的上一个位置开始的堆栈跟踪结束---

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在Microsoft.VisualStudio.TestWindow.Model.VirtualReadOnlyTestDataStore。< ProcessChange> d__57.MoveNext()

---从抛出异常的上一个位置开始的堆栈跟踪结束---

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在Microsoft.VisualStudio.TestWindow.Model.VirtualReadOnlyTestDataStore。< ProcessChange> d__56.MoveNext()

---从抛出异常的上一个位置开始的堆栈跟踪结束---

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在Microsoft.VisualStudio.TestWindow.Model.VirtualReadOnlyTestDataStore。<> c__DisplayClass55_0。<<< OnUnitTestChanged> b__1> d.MoveNext()

---来自先前位置的堆栈跟踪结束被扔了---

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在Microsoft.VisualStudio.TestWindow.Extensibility.ILoggerExtensions。< CallWithCatchAsync> d__4`1.MoveNext()


如果我关闭VS并重新打开解决方案,单元测试将会运行。


在调试模式下,在Release模式下传递的单元测试也会失败。当我调试测试时,它们在不同的位置失败,并且似乎没有调用shim函数。



解决方案

这只发生在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


这篇关于Visual Studio 2017在单元测试期间崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆