Peter Wilson
Peter Wilson

Reputation: 97

Vs2017 / C# weird debugger behavior

I am being plagued by weird behavior in a debug build of a C# project (target .Net Framework 4.7.2).

  1. The following code return false.
var wHasOvernightShifts = this.ScheduleSegments.Any(
    x => x.SegmentTypeId == eSegmentType.Schedule 
         && !x.IsDeleted 
         && x.ShiftDate == pShiftDate 
         && x.StartTime.Value.DayOfWeek != x.FinishTime.Value.DayOfWeek);

I know this to be the wrong answer. When I evaluate the RHS in Quick Watch (at the same point with the same data) the same code returns true. Step back the debugger and re-execute the statement returns false again. (n.b. All properties referenced have no side affects).

  1. I also have a method which seems to execute but returns null. A breakpoint inside the method is never triggered. Attempts to step into the function are ignored. The breakpoint says that it will not be triggered as the module is not yet loaded. However, a few lines higher in the source code a function from that same module behaves normally (w.r.t. debugging and expected function).

If I perform a clean and rebuild then everything behaves as expected. Note that a rebuild by itself is insufficient.

In case 2, following a clean/rebuild, the method returns a non-empty collection and the breakpoint inside it works, as does step-into.

It looks like the incremental part of the compiler is broken, or the execution environment has just forgotten that the module is loaded.

Has anyone else hit similar problems? Is there a simple solution (apart from clean/rebuild)?

n.b. I have turned off "Enable Just My Code" and turned on "Require source files to exactly match the original version" in an attempt to cure this problem - no luck.

Upvotes: 2

Views: 232

Answers (1)

Peter Wilson
Peter Wilson

Reputation: 97

It has been several weeks now since I updated the project to make sure that each configuration builds into a separate directory. The problem seems to have gone away.

I am pretty sure that this was the solution to the problem.

Upvotes: 1

Related Questions