Cannot debug tests using Resharper - Cannot Launch Debugger - c#

I'm not able to debug my tests using Resharper-Debug option in my project. I have seen this issue raised by lots of people, but has't come across a solid suggestion which solves my issue.
The strange thing is that, if I create a sample project and write a simple unit test, I'm able to debug it without any issues.However when I try to do this in my current project, it simply throws a dialog box saying "Cannot Launch Debugger".I have checked this with my peers, and they does't face this issue :(
Also I don't have any issues while running the test.
It's an XP machine and following is the version of resharper:
JetBrains ReSharper 5.1 C# Edition
Build 5.1.1753.4 on 2010-10-15T15:51:30
Licensed to: XXXXXXX
Plugins: none.
Visual Studio 9.0.21022.8.
Copyright © 2003–2011 JetBrains s.r.o.. All rights reserved.
Thanks,
-M

I occasionally encounter a test that can't be launched with the Resharper debug icon (due to mock objects or 32 vs 64 bit dlls). A solution that works for me is to add an explicit call to launch the debugger in the test
Debugger.Launch();
Then just run the test as normal. When code execution hits that line you get a security popup (pick yes)
then a visual studio choice popup (pick your currently running visual studio).
You'll be dropped into your code in debug mode at the location where you added the Debugger.Launch() line.

Possibly of use to someone stumbling here, specifically, I encountered the error:
---------------------------
ReSharper – Unit Testing
---------------------------
Cannot launch debugger.
Error code: 89710016
Error message: 0
when using R# 8.2 on VS 2013 Pro when attempting to debug NUnit tests.
After finding this link, the issue resolved by changing the NUnit class library project to x86 (Properties -> Build -> Platform Target : x86)

Instead of changing the build properties of the Project to be x86 (which can impact other team members if working on a team), you can tell Resharper to run the unit tests in a 32 bit process.
Resharper -> Options -> Tools -> Unit Testing ->General -> Default Platform Architecture
Set this to "Force tests to run in 32-bit process"

Changing to x86 did not work for me.
What worked was using Managed Compatibility Code in VS (2017) : Tools-> Options -> Debugging -> General -> checking Use Managed Compatibility Mode.
VS Pro 2017 15.7.6, R#2017.3.2

Related

Profile unit test in Visual Studio 2017 + NUnit + Resharper

I have a C# project in Visual Studio 2017 Professional. It has some unit tests: methods declared with [Test] which display a little green tick icon in the editor, where I can right-click and 'Run' or 'Debug' the test. When I do so, a window opens with all tests in the solution and I can click a green 'play' triangle to run them all.
I can also run my program under the profiler starting from Debug -> Performance Profiler.
So far so good. Now, how do I run a unit test under the profiler?
When I first asked this question I looked for profiling unit tests and saw it was a feature in Visual Studio Professional. But in fact, I'm not using VS's own unit testing support, but rather NUnit, driven by Resharper. Sorry to throw everyone off the scent.
Using VS2017 Professional and the Diagnostic Tools you can profile code between two break points!
Thus, you can debug your unit test (xunit, nunit, mstest, whatever!) with any tool (VS Test Explorer, ReSharper, etc) like this:
enable diagnostic tools while debugging (see answer from tm1)
Set a break point at the start of your unit test, another one at the end (or wherever you like)
Debug the unit test with your favorite tool, you hit the first break point.
Open the Diagnostic Tools window (Debug > Windows > Show Diagnostic Tools)
Start Recording a CPU profile (small record button below all those graphs)
Continue (F5) to the next break point
VS will now create a snapshot for this period and you can dig into the relevant methods. Voila!
Just for completeness, an alternative, commercial solution is Jetbrain's DotTrace, which is part of ReSharper Ultimate at the point of writing. Here you could directly profile your unit test without manual break points.
If you can debug and stop at a break-point, you should also be able to get CPU and memory usage according to this page, given you enable diagnostics tools while debugging.
Edit
According to #patrick-stalph the 3-step proposed solution does not work in Visual Studio 2017 Professional.
Disclaimer
I'm using Visual Studio Enterprise 2017, so I cannot check, whether this works in Professional, or not.
Open Test Explorer e.g. Ctrl + Q, then type Test Explorer and hit Enter
You should see your tests in Test Explorer. If you cannot, Build.
Choose a test, right click it, and choose Profile Test
Workaround
I must note, that I'm using xunit and autofixture, and I haven't seen this feature working. See this issue, why I haven't.
Hence, based on the answer of Jeremy Liberman, I was able to work around using the steps below:
Install xunit.runner.console NuGet package to the test project
Click Analyze > Performance Profiler... from the Toolbar.
Change Target to Executable
Click Start
Follow the Wizard, till you reach Choose the application that you want to profile (.EXE, .DLL, Website)
Choose An executable (.EXE file)
Based on Run tests with the xUnit.net console runner, I've specified the following values:
Full path: c:\<...>\src\packages\xunit.runner.console.2.4.0\tools\net472\xunit.console.exe (fit this to your environment)
Command-line arguments: <Product>.Tests\bin\Debug\<Product>.Tests.dll
Working directory: c:\<...>\src\ (the root of the Solution)
Next, Finish
Note, that this profiles all of the tests in the test assembly. You can choose, which tests you want to run by providing more Command-line arguments to xunit.runner.console. To learn more about the console runner options, run the console runner with no command line options.

Visual Studio 2015 - "Unable to step. The operation could not be completed. A retry should be performed"

When debugging I get the following error:
Unable to step. The operation could not be completed. A retry should
be performed
After clicking OK, the dialog returns:
The debugger cannot continue running the process. The operation could
not be completed. A retry should be performed.
The solution is set to "Debug" and "Any CPU". After restarting the application I can step through the code but it takes 5-10 seconds to step on something that normally goes instant. However CPU, RAM and HDD is operating normally and not peaking. Has anyone else experienced this?
I've also ran into this issue before in Visual Studio 2015 Update 3 on Windows 7 SP1 (64-bit).
Try disabling the Visual Studio hosting process.
Project Properties > Debug > uncheck "Enable the Visual Studio hosting process"
Also, are you running out of memory?
Are you debugging an ASP.NET website?
A known issue with the Visual Studio debugger causing this problem.
There is a race condition that happens when all of the following are
true:
Script debugging is enabled in IE
User is debugging IE and another process
The other process stops (hits breakpoint, step operation completes, stops at an exception, etc) at a moment when IE is not running script
code
IE starts running script code at roughly the same moment that the user hits F10/F5 in Visual Studio. The most likely reason for this to
happen is that the code from ‘setTimeout’ is run – there could be
other reasons as well.
Workaround
If you hit this problem, you can try detaching and reattaching the debugger.
-or-
This problem happens when debugging ASP.NET and when script debugging is enabled in IE. If you disable script debugging in IE, or
toggle it on and off when switching between debugger server-side and
client-side problems, you would be able to work around the issue.
-or-
If your web application is using setTimeout, you may be able to avoid or at least reduce the problem by doing something to ensure that
script runs less often. This could mean increasing the timeout value,
or this could mean adding conditions around when setTimeout is used.
Sources:
https://blogs.msdn.microsoft.com/rakkimk/2008/06/07/getting-unable-to-step-the-operation-could-not-be-completed-a-retry-should-be-performed-while-debugging-in-visual-studio/
https://blogs.iis.net/rakkimk/getting-quot-unable-to-step-the-operation-could-not-be-completed-a-retry-should-be-performed-quot-while-debugging-in-visual-studio
https://social.msdn.microsoft.com/Forums/vstudio/en-US/2320a943-d52d-437a-abec-6f1e9f929b52/debugger-error-unable-to-step-the-operation-could-not-be-completed?forum=vsdebug
Are you debugging a Universal Windows App?
If so, a work-around could be to reinstall "Tools for Universal Windows Appps Development" as follows:
· If the “Tools for Universal Windows Apps Development” are
still installed:
Go to Programs and Features, select Visual Studio 2105, click Change.
In Visual Studio setup, click Modify.
Deselect the feature “Tools for Universal Windows App Development”
Select “Tools for Universal Windows App Development” again, and click Update.
· If you have already uninstalled the “Tools for Universal
Windows Apps Development”:
· Reinstall “Tools for Universal Windows App Development”
· Or, take the following steps to reinstall the JavaScript
project system and language service:
§ Download the installer for your edition of Visual Studio, e.g.,
vs_community.exe.
§ Open a CMD window, and run the following command: vs_community.exe
/modify /installselectableitems JavaScript_Hidden /passive
Source:
- https://social.msdn.microsoft.com/Forums/vstudio/en-US/c9936d80-087d-4cad-93bf-ca4873889773/the-debugger-cannot-continue-running-the-process?forum=vsdebug
In Visual Studio 2015, 2017 and 2019 you can do that:
Go to Tools -> Options -> Debugging -> General
Turn off
"Break all processes when one process breaks"
Solved it by completely uninstalling Visual Studio and ReSharper. I used this tool:
https://github.com/Microsoft/VisualStudioUninstaller
After re-install everything worked again.
In my case detaching from the process and attaching again solved the problem.
I had a same problem but I had a single class library project in a solution so I just rebuild the solution and then it worked.

Display MSBuild warning in Visual Studio 2012

I work in a continuous integration environment.
Jenkins build my C# solution and display a lot of warning.
Here is an example of warning display :
In order to fix them, I want to get them in Visual Studio (and use vs' tools to debug them). Unfortunately, my warning list is empty :
How is it possible to configure VS 2012 in order to display MSBuild warning in Visual Studio ?
I already tried this link or this one, but doesn't work.
On the other side, when I browse the Code Analysis complete rules list, I cannot find the previous category :
Your CI Platform should be compiling in Release mode. Are you compiling in Release or in Debug within VS?
Code Analysis rule set are usually different between these two modes.

Visual Studio 2015 diagnostics tool does not support current debugging configuration

After using VS2015 snapshot and profiling tools, I can't seem to get the diagnostics tools to work again. Every project, even new ones just say the following
The Diagnostic Tools window does not support the current debugging
configuration.
Tried creating new and different type projects, running as administrator, deleting program data, app data, repairing and re-installing from uninstall.
Anyone experienced this?, shame as they've improved this tool a lot in this version.
So I resolved my issue. The Diagnostic Tools window currently does not support:
Windows Store projects that are using JavaScript
Windows Store projects that are running on a Windows Phone
Debugging with Use Managed or Native Compatibility Mode
In my case I had 'Use Managed Compatibility Mode' enabled. To change this go to the following and uncheck the 'Use Managed Compatibility Mode' or 'Use Managed Native Mode'.
Tools –> Options –> Debugging -> General -> (Un-check) 'Use Managed Compatibility
Mode'
I had the same problem but didn't have checked 'Use Managed Compatibility Mode' option. I had small research and seems like if start visual studio in Administrator mode, I'm able to use diagnostic tools. To start in Visual studio in Administrator mode just right-click on the studio icon and click on Run as administrator.
I encountered this error message in VS2017, but none of the above solutions worked for me. However, I did eventually get it to work.
It seems this tool can actually be attached to any process on the computer's CPU, not just the program being run by VS. So without specifying that you want to run diagnostics on program you're running from VS, it throws this error message.
Initially, I went to Debug > Windows > Show Performance Tools, and when I tried to run my program in the simulator, it would display that error message: "diagnostic tools window does not support the current debugging configuration". I tried going to Debug > Options and turning off the "Use Managed Compatibility Mode" feature, but it was already unchecked (and grayed out), and I tried running VS as an administrator, but it behaved the same.
Eventually, I found a post suggesting "Attaching to Process", which is what ended up working. I went Debug > Attach to Process, which opens up a window that lists a large number of available processes. I couldn't find the simulator that was running my program manually, so I opened my Task Manager, and found it: "qemu-system-x86_64".
I hit "Attach", then went back to Debug > Windows > Show Diagnostic Tools, and I was getting the stream I wanted. From there, I could take snapshots of my memory usage, and I had an easy way to observe the state of my program's memory leak problem during debugging without waiting for actual lag to build.
Cheers.
Running Visual Studio as administrator fixed this for me.
For me it was PostSharp 4.3 (alpha) breaking the "Diagnostics Tools" window.
Thanks for the pointer! For me, it was the other way around, though. "Use Managed Compatibility Mode" was unchecked. Checking it got rid of the error and the debugger started working again.

How do I get TestDriven.net to generate a useful code coverage XML file with NCover?

Steps to Repro:
Make a C# project in VS 2010 Professional on Windows 7 Ultimate 32-bit edition.
Write some unit tests with the VS C# Unit Test wizard
Download and install the latest RTM or Beta version of TestDriven.Net.
Right-click on the testing project and select Test With NCover
Wait
See that NCover's window is empty
How do I get TestDriven.net to generate a useful code coverage XML file with NCover?
So far, I've tried rebooting, uninstalling the RTM version and installing the Beta version, and running in Debug & Release modes.
Update with Output window text:
------ Test started: Assembly: TestProject1.dll ------
NCover v1.5.8 - Code Coverage Analysis for .NET - http://ncover.com
NCover.Console v1.5.8 - Code Coverage Analysis for .NET - http://ncover.org
Copyright (c) 2004-2006 Peter Waldschmidt
Command: C:\Program Files\TestDriven.NET 3\ProcessInvocation86.exe
Command Args: "/assemblyName:TestDriven.TestRunner.Server, Version=3.2.2770.0, Culture=neutral, PublicKeyToken=50ecb853f8c6b8d2" "/xmlName:M:TestDriven.TestRunner.Coverage.NCoverCoverageTestRunner.OutOfProc.Run(System.String,System.String,System.String,System.String,System.String)" "/parameter:tcp://127.0.0.1:64445/7dbdb535-3602-4a8e-8bbc-f8be7eb83987" "/parameter:tcp://127.0.0.1:64445/fbff4f73-2438-43e4-b1f9-2bdaeb9c0907" "/parameter:C:\Users\Zian\Documents\Visual Studio 2010\Projects\ClassLibrary1\TestProject1\bin\Debug\TestProject1.dll" "/parameter" "/parameter"
Working Directory:
Assemblies: ClassLibrary1;ClassLibrary1_Accessor;TestProject1
Coverage Xml: C:\Users\Zian\AppData\Local\Temp\Mutant Design\TestDriven.NET 2.0\Coverage\ClassLibrary1\TestProject1.xml
Coverage Log: Coverage.Log
Waiting for profiled application to connect...Connected
Configuring Profiler...
******************* Program Output *******************
Unable to establish communications with the profiler. (0x2)
NCover couldn't create a coverage report.
(Assuming you are using NCover 1.5.8 which ship with TDD.Net)
I've done exactly what you described, and it works just fine...
Here are some things to consider:
Are you sure the actual xml file is empty? Try to look for it here:
C:\Users\USERNAME\AppData\Local\Temp\Mutant Design\TestDriven.NET
2.0\Coverage\YOURPROJECT, or use something like Everything (great free search tool) to find YourTestProject.xml. Perhaps there is a problem with the NCover GUI.
There have been some problems with MSTest & NCover integration prior
to 1.5.8. Try to reproduce this with NUnit and see what happens
(Actually IMHO, I don't see any advantage for MSTest over NUnit
anyway).
Are you running any other profiler in addition to NCover? Is
so, try to disable them.
EDIT:
Try to follow the steps in this article. There's a section called "NCover With TestDriven.NET".
It seems as NCover's profiler is not registered properly, so mainly what you have to do is remove it manually completely (TDD.Net probably doesn't do it for you), and only then reinstall it.
Uninstall the Beta version of TestDriven.net
Install the RTM version of TestDriven.net
The 2 steps work because NCover's profiler is not registered properly, as described by KiwiDude.

Categories

Resources