96

Background

I have an ASP.NET MVC application project, along with various other projects within a Visual Studio solution. The different projects use various versions of the NPoco library as follows:

  • The MVC project includes a version of NPoco through NuGet.
  • Some other projects include a (probably different) version of NPoco through a reference to a DLL (not the DLL provided through NuGet).
  • One of the projects is the source code of a version of NPoco with some alterations made.

I'm using Visual Studio 2015 Update 3 14.0.25422.01.

Error

For some reason, when I launch this application in the debugger using the normal Start Debugging command in Visual Studio, it launches, but it also produces the following warning:

You are debugging a Release build of NPoco.dll. Using Just My Code with Release builds using compiler optimizations results in a degraded debugging experience (e.g. breakpoints will not be hit).

If I press Continue Debugging, everything seems to still work as usual, including breakpoints.

This problem only started happening recently.

Question

  1. Anyone know what caused the above error?
  2. Do I have something misconfigured?
Community
  • 1
  • 1
Sam
  • 40,644
  • 36
  • 176
  • 219

27 Answers27

90

Disable this option under Debug->Options->Suppress JIT optimization on module load (Managed only).

A connect report submitted before:

https://connect.microsoft.com/VisualStudio/feedback/details/2116788/flag-optimize-is-passed-to-the-debugger-even-while-the-build-settings-optimize-code-is-not-enabled-on-mvc-c-web-projects-when-using-just-my-code.

Please also make sure that all projects are in debug mode, Optimize code was unchecked like this case:

VS2015 Project no longer runs in debug mode

Community
  • 1
  • 1
Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • 60
    Thanks. The **Suppress JIT optimization on module load** setting was disabled, but the problem stopped happening when I enabled it. – Sam Jul 28 '16 at 01:53
  • You are welcome, at least, we know that it is really related to this debugging option. – Jack Zhai Jul 29 '16 at 02:01
  • Thank you - The solution you suggested worked! **Note:** The Microsoft feedback link is not reachable, it shows: "Page Not Found - The content that you requested cannot be found or you do not have permission to view it." – Matt May 12 '17 at 08:57
  • 1
    But what is this checkbox? Does "Continue Debugging (don't ask me again)" just check it for you? what are you losing from checking this box? – MistaGoustan Dec 27 '18 at 18:57
  • I think you mean "enable this option". That worked for me, but looking at the problem project it had Build -> Optimize code enabled, and disabling that worked as suggested below by Mahesh Malpani. – Nick Westgate Sep 24 '19 at 06:27
  • @sam What you explained here works for me too Thanks A lot – Khareem Dec 06 '19 at 18:39
  • JIT optimization default setting was disabled, but the problem solved after I enabled it, anyways, Thanks a lot, <3 – Shammie Aug 10 '20 at 05:11
  • 1
    I went with Sam's suggestion, but after reading [the docs here](https://learn.microsoft.com/en-us/visualstudio/debugger/jit-optimization-and-debugging?view=vs-2019) decided to try again. I spotted a build warning stating that some modules were optimized but I had `Enable Just My Code` set. I then reverted `Suprress JIT Optimization on module load` to its original value (selected) but de-selected Enable Just My Code. I am able to debug now. – Veverke Aug 23 '20 at 11:53
31

"Optimize code" option is there on visual studio project level. Remove that for debug mode.

Mahesh Malpani
  • 1,782
  • 16
  • 27
27

I also encountered the similar problem in Visual Studio 2019 Following Steps solved my issue Debug-> Options->Uncheck Enable Just my code option

Sneha
  • 428
  • 4
  • 10
22

Just had a similar issue that I was able to fix by Cleaning my solution 3 times and rebuilding. Hope this helps other people too.

tokyo0709
  • 1,897
  • 4
  • 28
  • 49
17

Right click on your solution and select Properties.

Then, go to Configuration Properties on the left and select Configuration under it. Make sure that the Configuration of the project you are running is in 'Debug' and not in 'Release'.

If the Configuration is in 'Release' you would get this error.

StarLord
  • 707
  • 1
  • 8
  • 21
9

This happened to me while using NuGet packages.

Let's say you want to debug code from Project1...

If you have a Project1 NuGet package referenced in any of the projects in the solution (.sln), make sure you remove it. Instead of adding Project1's NuGet package, add Project1 (.csproj) directly as a reference to any given project that needs Project1 in the solution. This way you'll be able to step through code while debugging and Visual Studio won't bark about "Release" version anymore.

If Project1 is from a different solution (.sln), you can right click your current solution and select Add existing item... pick Project1.csproj for example. Then go to any project that needs Project1 => right click => Add => Reference and pick Project1.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
  • *add **`Project1`** (.csproj) directly as a reference **to any given project*** - this should be stressed :) – OfirD Aug 22 '23 at 09:29
5

I have found that when you update a Nuget package that has a dependency on a referenced project (that you may have modified version) it replaces this with the Nuget version of the dll.

To fix this after updating (or adding) you nuget package you need to remove the reference to the dll (e.g. NPoco) and the add a project reference to the project with your modified version.

TrtlBoy
  • 669
  • 14
  • 17
  • 1
    same here... started right after adding a nuget package.. At first the re-referencing fix had no affect; even after rebuilding. I had to restart VS. Then it cleared up. @TrtlBoy, thanks for your help. – puddleglum May 22 '17 at 22:04
  • A simple rebuild fixed mine. Thanks @puddleglum. – Reid Jun 01 '17 at 18:12
  • 1
    To add to this, if you uninstall a nuget package from your project and add a reference directly to the project, make sure nothing else in the solution is using the nuget package. In my case there was another csproj that was still using the nuget package, and it produced this message. I uninstalled the nuget package from all projects and re-added the references manually. – NibblyPig Mar 29 '18 at 09:07
  • Great Answer! When in a solution testing, reference the project directly, not the nuget. No need to restart VS. You may get issues if you have multiple projects referencing this. But you don't need more than a test project included anyways – Nick Turner Jun 02 '20 at 14:14
4

In my case, I had Optimize code checked for my Debug build configuration. Make sure this is unchecked for all Debug configurations across all projects.

enter image description here

John Livermore
  • 30,235
  • 44
  • 126
  • 216
3

In my case some tricky trickster put this into the AssemblyInfo.cs file:

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]

Commented it out and it started working

Adam Plocher
  • 13,994
  • 6
  • 46
  • 79
  • I'm glad that helped. I should mention that I later found out that this particular project was decompiled from a "Release" build of a project that my company lost the source code for! So it's probably a common thing to find in any "Release" assembly that gets decompiled. – Adam Plocher Nov 18 '19 at 21:24
3

You can see the solution whit this link: https://social.msdn.microsoft.com/Forums/vstudio/en-US/d70966e3-794f-4b48-88e1-3dd44a65be89/dubugger-doesnt-work-quotyou-are-debugging-a-release-buildquot?forum=visualstudiogeneral

Change To Debug the select list enter image description here

2

Right click solution > Properties > Configuration Manager > Active solution configuration : New
Give a name to new solution configuration. Copy setting from "Debug".

I did everything for this error but just this solution worked.

barbsan
  • 3,418
  • 11
  • 21
  • 28
1

In case someone is still having this issue, for me it was because I confused the GAC by installing the software I was trying to debug.

The fusion logger helped me figure this out ha.

1

In my case I removed Webapplication.dll for my project and removed contents in release folder. Rebuild project again and it works for me.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
1

Another reason for this problem is the following "assembly-level" attribute:

[assembly: System.Diagnostics.Debuggable(true, false)]

(I found this out only by accident....who checks AssemblyInfo.cs when one experiences such problems....right - nobody)

Edit: just saw that someone else added this already..... (with other parameters though) - also - the reason for this attribute was also "decompile from exe" (we lost source-code for that particular project :-/ )

1

I had the same issue after moving my projects to a new machine.

Downloading the proper Target framework worked for me. My project uses .Net Framework 4.7.2 and the error went away after downloading .Net Framework 4.7.2.

user1619768
  • 53
  • 1
  • 1
  • 7
1

Short answer (FIX):

Enable the option to Suppress JIT optimization on module load in Tools->Options->Debugging->General

Enable this option

The reason: If you are trying to debug code, it is easier when that code is NOT optimized. When code is optimized, the compiler and runtime make changes to the emitted CPU code so that it runs faster, but has a less direct mapping to original source code. If the mapping is less direct, debuggers are frequently unable to tell you the value of local variables, and code stepping and breakpoints might not work as you expect.

How it works: The debugger exposes an option that controls what happens when a DLL that is compiled with optimizations enabled loads inside of the target process. If this option is unchecked (the default state), then when the .NET Runtime compiles the MSIL code into CPU code, it leaves the optimizations enabled. If the option is checked, then the debugger requests that optimizations be disabled.

More info

0

This happened to me in VS2017, even after changing the configuration to Build. The issue was resolved when restarting VS2017

Elayamathy
  • 189
  • 2
  • 5
0

This is one of typical Microsoft errors that could have 20 solutions. For me, I rebooted my server that was running visual studio 2017 and it fixed the issue.

PhillyNJ
  • 3,859
  • 4
  • 38
  • 64
0

I encountered this problem (in Visual Studio 2017) for the first time today. For me, it turned out to be caused by a different version of my application, built in Release mode, running under the same application pool in IIS that I was debugging with. I gave the different version of the application its own application pool and the problem disappeared.

0

This started happening randomly in the middle of the day for me.

Tried Clean, deleted all BIN and OBJ folders... nothing worked.

I had to stop/start the IIS application pool for the ASP.NET solution to fix it.

Glen Little
  • 6,951
  • 4
  • 46
  • 68
0

Had some advanced settings in ProjectName.csproj.user. After deleting, it worked

SzilardD
  • 1,611
  • 2
  • 22
  • 40
0
  1. Close VS
  2. Delete all bin & obj folders inside your project

PowerShell snippet for deleting all bin and obj folders and files:

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Kaloyan Drenski
  • 950
  • 1
  • 13
  • 18
0

One common case is not mentioned in the existing answers:

When Debugging a "chain" of referenced dlls, all of the dlls must be referenced from the first dll in the chain.

As an example, let's say we have this structure:

A.dll, which references:
  B.dll, which references: 
    C.dll

In this example, if we want to debug C.dll, the current reference chain is not enough, and we must make A.dll reference C.dll as well:

A.dll, which references both:
  1. B.dll, which references: 
       C.dll
  2. C.dll
OfirD
  • 9,442
  • 5
  • 47
  • 90
0

I kept getting this "error" even though I changed the Configuration dropdown to "Debug" which didn't work. I eventually clicked on Build > Configuration Manager and changed it to "Debug" and the error went away.

Hugh Seagraves
  • 594
  • 1
  • 8
  • 14
-2

Close and Restart visual studio worked for me

-2

After reading through the myriad solutions above, I exited from VS and restarted it. Yes, that's right, I turned if off and on again. And, yes, it worked.

-2

Just select "Continue Debug (don't ask again)"

This is how it has always worked. They added this new message for the newbies that don't realize that debugging does not work (that well) when optimizations are used (like in release mode)

Some of the other suggestions above are problematic