31

Using Windows 7 32 bit, VS 2010, .NET 4 DLL, NUnit (2.5.5) to unit test the application. I'm currently getting the following error; seen plenty of posts and tried the following:

  1. restart machine
  2. restart VS
  3. delete bin/obj and reload
  4. clean/rebuild

But I cannot get NUnit to hit my breakpoints when running;

I set the NUNit test project to point to the nunit.exe, and to load the testing .NET 4 DLL, but when I run it doesn't find the breakpoint, "no symbols have been loaded". I tried debug >windows > modules, it doesn't even show my unit testing project when I run it.

I found this, to use the nunit agent: http://groups.google.com/group/nunit-discuss/browse_thread/thread/5680d7def5b6982f

But I get an error when I use the nunit agent too. I was using nunit-agent-x86.exe, but I get a system.formatexception and it crashes...

Can anybody help?

Thanks.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257

9 Answers9

43

There's another similar question here on Stack Overflow, where I posted my answer with what worked for me. I can set breakpoints and start NUnit directly from Visual Studio 2010 with Debug -> Start New Instance (which I think is your goal).

I set nunit.exe as the external program in project -> Properties -> Debugging and added:

<startup>
    <requiredRuntime version="4.0.30319" />
</startup>

to the nunit.exe.config file found next to the nunit executable in the NUnit install directory.

Community
  • 1
  • 1
Dave Bacher
  • 15,652
  • 3
  • 63
  • 86
  • 1
    Adding section to the .config file worked for me. Btw, it goes directly under – Jan Hettich Sep 26 '10 at 00:58
  • @Jan: You're absolutely right, only putting it on the top works! – abatishchev Jan 24 '11 at 16:23
  • 3
    thanks for the solution. Please consider this the accepted answer. Notes, this worked for me: is in , and using – erict Aug 06 '11 at 01:52
  • This fixed the problem for me as well, running NUnit 2.5.7. It worked for the config files for both nunit.exe and nunit-x86.exe. – ACK_stoverflow Apr 18 '12 at 21:18
  • This fixed the issue for NUNit 2.6 on a x64 machine. The following nunit.exe.config did not work - I needed the config Dave gave above. – Paul Jul 23 '12 at 18:29
16

The resolution was: start NUnit stand alone, then in VS 2010, do debug > attach to process, and attach to the nunit-agent.exe process, not the nunit process. Nunit process still didn't do it for me.

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • This problem is driving me nuts! I have one project where Visual NUnit won't work, and launching my tests project with nunit-x86 as the external program doesn't work, nor does attaching to nunit work. I also don't have an nunit-agent.exe in my list of processes, only nunit-x86. Have you seen this before? – Dave Dec 14 '10 at 17:57
  • Nunit can run your tests in a separate process within the runner, which can lead to the debug symbols not being loaded even if you're attached to the nunit.exe process. Check your settings in visual nunit. It can also run each assembly of tests i a separate process, making it very hard to attach. – Massif Jan 24 '11 at 16:18
  • Attaching to the nunit-agent-x86.exe process solved the problem for me. Thank you! – Jan Hettich Sep 07 '11 at 02:43
  • This solution is also worked for me, I was regular to attach nunit with visual studio 2008 to nunit process and not to the nunit-agent.exe process – Delashmate Oct 18 '11 at 08:46
  • This solution worked for me too. I was just not able to debug my NUnit project earlier. Also, I am using NUnitRunners Nuget package. But I don't think that makes any difference. Now I have another question - how can I tell VS 2010 to tell to attach to nunit-agent automatically when I run an NUnit project? I don't want to attach the stuff manually again and again. – Kumar Vaibhav Apr 18 '13 at 09:41
  • My problem just got another fix - I added to nunit.exe.config and everything works like a charm. – Kumar Vaibhav Apr 18 '13 at 09:48
  • i have attached the nUnit-x86.exe, that's perfectly work for me. – Vignesh Paramasivam Oct 30 '13 at 07:32
1

If all of the above did not help, open the Properties of your NUnit project in Visual Studio, open "Build" tab, click the "Advanced" button and make sure "Debug Info" is set to "full"

1

I was getting "break point will not be hit ... no symbols loaded ..." for a website project. Found that there were build errors in my website (one of the referenced dll's went missing for some reason). Rebuilds didn't show the problem until I selected View=>Error list in VS2010, prior to the rebuild. Replacing the missing dll in the bin dir & updating the reference solved my problem.

JimBayne
  • 11
  • 1
1

Adding the following section in the nunit-x86.exe.config worked for me:

  <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>

The 'sku' section is only needed when running with .NET 4's Client Profile. Note that a previous answer showed using 'requiredRuntime' which is obsolete.

Daniel
  • 8,794
  • 4
  • 48
  • 71
0

Attach nunit-agent.exe process instead of nunit.exe because when dotnet version is different form what is used by nunit it self, nunit execute the task by nunit agent. See the link below.

http://www.nunit.org/index.php?p=nunit-agent&r=2.5.10

Manasvi Sareen
  • 916
  • 7
  • 17
0

Are you running NUnit and then loading the DLL? Try instead opening the project properties, Debug tab, switch the start action to 'Start external program', point to the NUnit exe, put your dll name in 'command line arguments'. Then start the library project right-clicking it and choosing Debug -> start new instance.

Mau
  • 14,234
  • 2
  • 31
  • 52
  • I was doing both; standalone, or running the project with nunit. Still no luck, get same issue... – Brian Mains Jun 20 '10 at 18:33
  • this doesn't work for me either. I'm still researching the issue to try to figure out how to get it to work. – Dave Dec 14 '10 at 17:58
0

This problem occurred to me under Visual Studio 2012 Community Edition, when working with .NET Framework 4.5. nunit.exe.config should like this (solution from the most appreciated answer):

<configuration>
    <!--
   The GUI only runs under .NET 2.0 or higher. The
   useLegacyV2RuntimeActivationPolicy setting only
   applies under .NET 4.0 and permits use of mixed 
   mode assemblies, which would otherwise not load 
   correctly.
  -->
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <!-- Comment out the next line to force use of .NET 4.0 -->
         <requiredRuntime version="4.0.30319" />
    </startup>
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
0

I needed to open the NUnit GUI

Tools->Settings->IDE Support [click Visual Studio]

Then in the nunit-x86.exe.config (NOT nunit-exe.config, NOT nunit.agent.exe.config, NOT nunit-console.exe.config),

I needed

   <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319" />
  </startup>

under <configuration>

patrick
  • 16,091
  • 29
  • 100
  • 164