.net - NUnit测试PLINQ代码后,如何防止AppDomainUnloadedException?

标签 .net nunit appdomain plinq parallel-extensions

如何诊断和最小化或防止AppDomainUnloadedException

在涉及PLINQ的长时间(> 10s)测试之后,NUnit 2.5.2始终抛出AppDomainUnloadedException

早在2008年7月,Stephen Toub said:

Yes, the scheduler in the CTP doesn't handle thread aborts very well, which frequently causes the process to crash when a live scheduler exists in a domain being shutdown (since AppDomain shut down causes thread aborts on all threads with stack frames in that domain). We're working to harden this for a future release.



我尝试了许多解决方法,包括:
  • 使用单独的方法运行测试以消除杂散引用
  • 指定/domain:None作为NUNit参数
  • legacyUnhandledAppDomainPolicy删除nunit-console.exe.config元素

  • 我无法将NUnit降级到reduce the odds of the race condition,因为我需要PLINQ来使参数测试更快。没有问题的NUnit版本不支持参数测试。

    最佳答案

    根据this PLINQ Task Manager thread on the MSDN forums,您的问题应该得到解决;在.NET Framework的最新版本中,PLINQ的任务管理器已在AppDomain卸载时彻底关闭。

    .NET 4或4.5是否仍遇到此问题?

    关于.net - NUnit测试PLINQ代码后,如何防止AppDomainUnloadedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1340187/

    相关文章:

    NUnit Assert.Equals 与 Assert.AreEqual

    c# - 是否可以在同一个 AppDomain 上托管 WebMethods 和 ASP.NET 应用程序?

    .net - 标准 ASP.NET header 从哪里出现?

    c# - 在自定义类中处理异常

    c# - 在双显示器的屏幕中央显示表格 如何?

    c# - NUnit - 断言异常和属性

    unit-testing - 在测试用例中包含预期结果是一种好习惯吗?

    c# - AppDomain 中 Enum 的奇怪 SerializationException

    .NET 程序集加载

    c# - 如果 .net 框架(32 位或 64 位)是使用 'Any Cpu' 配置构建的,应用程序将在 64 位 Windows 上使用