Unable to get value because it has been optimized

I have a problem with debugging ... Suddenly I do not see the values โ€‹โ€‹of most variables during debugging. I managed to get two different messages in the Immediate window:

It is not possible to get the value of a local or argument "parameter" because it is not available when specifying this instruction, possibly because it has been optimized.

and

Internal error in evaluating an expression.

I have tried and checked the following things:

  • Solution configuration configured for debugging ( not )
  • Project โ†’ Settings โ†’ Build โ†’ Optimized code is not installed
  • Tools -> Options -> Debugging -> Use Compatibility Mode with Managaed (doesn't work)

Do you have any further ideas on how I can properly debug again ?: (

Thanks in advance

Edit Code is nothing special. This happens when I try to see what's inside the [Key] parameter

public void AddOrUpdateQuartzJob(string jobName, IList<KeyValuePair<string, string>> parameters) { var jobDetail = this.GetJobDetail(jobName); if (jobDetail != null) { foreach (var parameter in parameters) { jobDetail.JobDataMap[parameter.Key] = parameter.Value; } } else { this.ScheduleNewJob(jobName, parameters); } } 
+12
debugging c # clr
source share
4 answers

The best way I found to convince the JIT compiler not to optimize the code was to use an INI file with the assembly name in the same folder as the assembly with the contents :

 [.NET Framework Debugging Control] GenerateTrackingInfo=1 AllowOptimize=0 

Note that this should be the name of the assembly, not the name of the EXE process (unless it is the EXE assembly that you want to debug). For example. if you have the assembly MyCode.dll , the INI file name will be MyCode.ini .

Below are some slides from the presentation on .Net debugging that show the difference:

Optimization:

Optimized debugging

Without optimization:

Debugging without optimization

+13
source share

Go to โ†’ Project Properties โ†’ in the Assembly section โ†’ check the "Optimize code" box. Not marked.

In addition, In the "Project Properties" section โ†’ "Assembly" โ†’ "Advanced" โ†’ set the "Debug Information" drop-down menu to "Full" in "Parameters"

+2
source share

After making the changes listed in Codecain and Inanka Talagal, be sure to clear, rebuild and publish to make the changes effective.

0
source share

For anyone else puzzled by this, you can make the same simple mistake I came across: my build mode was set to Release from another project that I had to build for release earlier that day. Flip it back to Debug; the problem is solved.

0
source share

All Articles