axodox / AxoCover

Nice and free .Net code coverage support for Visual Studio with OpenCover.
https://marketplace.visualstudio.com/items?itemName=axodox1.AxoCover
MIT License
250 stars 60 forks source link

"Could not create service" exception when clicking Cover, Cover tests, or building with 'Cover after every build' turned on. #109

Open alewkowicz opened 7 years ago

alewkowicz commented 7 years ago

I'm getting an error in the AxoCover Output window pane when I click the Cover option in the header bar, the Cover tests option in the context menu, or build with "Cover after every build" turned on (via the Context menu).

Please let me know what additional information you would like. AxoCover is a great tool and I'm glad to have found it!

Here's the contents of the Output window pane:

Test execution started.
AxoCover encountered an error:

Test execution failed.
SerializableException: Could not create service.
   at AxoCover.Models.TestProcess`1..ctor(IProcessInfo processInfo) in C:\projects\axotools\AxoCover\Models\TestProcess.cs:line 36
   at AxoCover.Models.ExecutionProcess.Create(String[] testPlatformAssemblies, IHostProcessInfo hostProcess, TestPlatform testPlatform) in C:\projects\axotools\AxoCover\Models\ExecutionProcess.cs:line 28
   at AxoCover.Models.AxoTestRunner.RunTests(TestItem testItem, Boolean isCovering, Boolean isDebugging) in C:\projects\axotools\AxoCover\Models\AxoTestRunner.cs:line 176
   at AxoCover.Models.TestRunner.<>c__DisplayClass31_0.<RunTestsAsync>b__0() in C:\projects\axotools\AxoCover\Models\TestRunner.cs:line 53

The Build version is 1.1.244 per the Settings window. The last check for updates was today.

Microsoft Visual Studio Professional 2017 Version 15.2 (26430.16) Release VisualStudio.15.Release/15.2.0+26430.16 Microsoft .NET Framework Version 4.6.01590

Installed Version: Professional

I have telemetry turned ON for AxoCover.

riccardone commented 7 years ago

I fixed this running Visual Studio as Administrator

biltongza commented 6 years ago

I get this too sometimes. The root cause seems to be environmental I think, because when we run our tests connected to the network at the office through VS test runner, it takes about 15 seconds for the tests to actually start. Disconnecting from the network seems to remove this delay immediately.

This leads me to believe it might be AxoCover timing out the service creation.

Whenever this happens, I just try running it again until it works, which it usually does within the next 3 tries.

axodox commented 6 years ago

Service timeout is 20 seconds right now. This timeout is before the runner is ready to execute the tests. The runner listens to the UI at a random TCP port on loopback device (127.0.0.1).

Can you check if the runner (AxoCover-Host) crashes in the windows application event log? It should also provide a stacktrace there if it crashed.

Unfortunately I cannot reproduce this problem, but if you have some time I can give you information on how to debug it. Until that I can improve telemetry in regards to this, since it was not providing enough info to fully understand / reproduce the problem so far.

axodox commented 6 years ago

I am suspecting that a firewall or antivirus might interfere with the communication with the runner. I have made a build which uses NamedPipes instead of TCP based communication. Can you try it?

It is here.

alewkowicz commented 6 years ago

Unfortunately, I can't try it, as I am no longer working at the client site where I experienced the problem. I don't have a copy of the source code for that project. Nor do I have access to that desktop machine, as it belonged to the client.

Perhaps @riccardone or @biltongza could try it?

Thank you for working on the problem!

biltongza commented 6 years ago

Tried it, still the same issue.

Test execution failed.
SerializableException: Service creation timed out.
   at AxoCover.Models.TestProcess`1..ctor(IProcessInfo processInfo) in C:\projects\axotools\AxoCover\Models\TestProcess.cs:line 31
   at AxoCover.Models.ExecutionProcess.Create(String[] testPlatformAssemblies, IHostProcessInfo hostProcess, TestPlatform testPlatform) in C:\projects\axotools\AxoCover\Models\ExecutionProcess.cs:line 28
   at AxoCover.Models.AxoTestRunner.RunTests(TestItem testItem, Boolean isCovering, Boolean isDebugging) in C:\projects\axotools\AxoCover\Models\AxoTestRunner.cs:line 86
   at AxoCover.Models.TestRunner.<>c__DisplayClass31_0.<RunTestsAsync>b__0() in C:\projects\axotools\AxoCover\Models\TestRunner.cs:line 53

Running the coverage test again immediately afterwards worked. I'll continue trying to see what happens to get you some more results.

axodox commented 6 years ago

Do you have a case where only the first case fails, but it tends to be work after. Maybe a slow HDD or antivirus could be the source of the problem?

axodox commented 6 years ago

Also I see a failed runner start for a user in telemetry in the last hour, however it still uses TCP. Are you sure you use the right version? Do you have telemetry enabled?

biltongza commented 6 years ago

I'm sure it's the right version, build 1.1.271. I have telemetry enabled, but I'm not sure if it was enabled when I ran that test last time.

That said, I just started a coverage run from a cold start of my machine this morning, and it worked first time.

I don't think it's HDD related, since I'm on an SSD. I could believe antivirus being the source of the issue, but I can't test it because we can't disable the AV (corporate policy).

I'll be honest I don't know if there is a "fix" for this as I think it's environmental, but it would be nice if I could configure the service creation timeout period and see if I can work around it like that.

axodox commented 6 years ago

Ok, I think I will add some developer options, namely:

Hopefully this will help to understand the issue.

axodox commented 6 years ago

I have added the following features to help us figure out the issue:

image

JakenVeina commented 6 years ago

So, I took the new release to work today expecting to come home with a better error message about why coverage wasn't working.

Coverage works fine now.

:/

JakenVeina commented 6 years ago

The "Could not create service" exception resurfaced today. The new "Debug" option did not provide any new messages in the Output window.

biltongza commented 6 years ago

Still getting this issue. Debug mode is enabled but I'm not getting any extra information in the output window. Telemetry is enabled so you might be able to see more than I can. Increasing the startup timeout from 20 seconds to 60 seconds seems to have helped, though.

richarth commented 6 years ago

I've also go this issue in VS 2017. I've increased the startup and debugger timeouts to 120 but it hasn't had any effect.

I've also enabled debug mode but I'm not seeing any additional output in the output console either.

sanyizaresz commented 6 years ago

Hi, I think, the issue might be related to the settings. For example, when I set the "Exclude directories" to "D:\mysource\mystuff\mymodule\" then the "Cover tests" action fails (immediately, so the timeout thing is ignored). When I set it to "\mystuff\mymodule" (I removed not just the "D:\" but the last backslash as well) then the "Cover tests" action started to work again.
I hope it helps:).

Nila-Loeber commented 6 years ago

FWIW, I had the "Could not create service." error as well. Turned out it was related to a Test Project assembly's name containing whitespace. When I renamed the Test Project's assembly, the error disappeared.

zoltan-hadur commented 6 years ago

Got this exception when I had these filters in the settings.json: "Filters": "+[Some.Namespace.*]* -[Some.Namespace.*.Test]*\"", instead of these: "Filters": "+[Some.Namespace.*]* -[Some.Namespace.*.Test]*", Notice the one little quote at the end of the first line.

auroraeosrose commented 5 years ago

This bug is definitely related to whitespace and quotation marks in settings entries

https://github.com/axodox/AxoCover/blob/master/AxoCover/Models/Testing/Execution/OpenCoverProcessInfo.cs#L84

This appears to be causing issues when sending args to opencover console.exe

https://github.com/opencover/opencover/wiki/Usage

I haven't dug around in the code enough to figure out exactly where the issue is - but any kind of quotes in the exclude values will cause the serializableexception to fail

But not using quotes means you can't ignore anything with spaces apparently