7

I am developing an application using dotnet core. When I try to run the unit tests, I receive the following message:

The active test run was aborted. Reason: Unable to communicate with test host process. 

I already checked my .csproj files, I have uninstaled and instaled again dotnet core, tried to rebuild the projects, tried to restore the packages again, searched for code errors, but I have no clue of what is happening.

I am using Ubuntu 16.04.

The project that is facing the issue is available here: https://github.com/andremteixeira/Personal-Accounting

1 Answer 1

10

You have created a stack overflow exception that unfortunately completely crashes the test host process..

The problem is:

  1. Any operator is called
  2. This calls CheckNullity
  3. CheckNullity has a a == null comparison
  4. This invokes the custom bool operator == (Money a, Money b)
  5. Which forwards to bool IsEquivalent(Money a, Money b)
  6. Which has a check for a != null
  7. Which invokes the custom operator bool operator != (Money a, Money b)
  8. Which has a check for a == null
  9. This lands at 4. again

if I replace

if (a == null || b == null) 

with

if (Object.ReferenceEquals(a, null) || Object.ReferenceEquals(b, null)) 

in CheckNullity it breaks the cycle and all the tests run.

Sign up to request clarification or add additional context in comments.

5 Comments

how did you figure it out?
dotnet test -d diag.log printed a stack overflow exception (sadly without stack trace) so I looked for places that could cause one..
wow. That would took a lot of experience with the language. Thank you!
Hey, Martin. When I came home today and tested your solution, it still didn't work. Can you help to figure it out? I see you have a very good expertise and can help me solve this. I would appreciate. :)
Its me again. I've found more places in my code with the same situation that generated the stack overflow and applied your suggestion. Now it works perfectly. Yay! :D