102

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?

27 Answers 27

96

Disable this option under Debug -> Options -> Suppress JIT Optimization on Module Load (Managed only).

A connect report previously submitted:

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.

Also make sure that all projects are in debug mode; optimize code is often unchecked, like this case:

Visual Studio 2015 project no longer runs in debug mode

8
  • 62
    Thanks. The Suppress JIT optimization on module load setting was disabled, but the problem stopped happening when I enabled it.
    – Sam
    Jul 28, 2016 at 1:53
  • You are welcome, at least, we know that it is really related to this debugging option.
    – Jack Zhai
    Jul 29, 2016 at 2: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, 2017 at 8: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? Dec 27, 2018 at 18:57
  • 1
    I went with Sam's suggestion, but after reading the docs here 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, 2020 at 11:53
33

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

3
  • this was the case for me in VS2022 old project, thx.
    – Honza P.
    Feb 7, 2022 at 11:50
  • Very nice, this happens in VS 2022 as a new thing on my project. Thanks for the tip wish it was in the dialog that comes up.
    – Carter
    Feb 23, 2022 at 18:20
  • This was the solution for me on Visual Studio 2022 after several hours of working on this issue.
    – jon.r
    Apr 5, 2022 at 16:54
30

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

2
  • Nice, it works as a charm, Thanks... Sep 27, 2021 at 6:02
  • This helped in mine case as well. Aug 22, 2022 at 4:51
24

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.

0
21

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.

3
  • 2
    This is it, Thanks! Oct 14, 2020 at 15:39
  • 1
    Change from debug to release in MV sol configuration dropdown list Feb 12, 2021 at 9:23
  • 1
    Worked perfect for me in VS2019 for ASP.NET Core project. thanks.
    – ramya
    Jun 17, 2022 at 17:42
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.

1
  • add Project1 (.csproj) directly as a reference to any given project - this should be stressed :)
    – OfirD
    Aug 22, 2023 at 9: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.

4
  • 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, 2017 at 22:04
  • A simple rebuild fixed mine. Thanks @puddleglum.
    – Reid
    Jun 1, 2017 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, 2018 at 9: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 Jun 2, 2020 at 14:14
4

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

1
  • wow i cant believe i didnt notice this. Thank you
    – d0rf47
    Oct 28, 2022 at 17: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

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

1
  • 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. Nov 18, 2019 at 21:24
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.

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.

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.

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

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.

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.

0

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

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 }
1
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
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.

-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

Not the answer you're looking for? Browse other questions tagged or ask your own question.