Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Null when hovering over a variable
benjohnston
#1 Posted : Wednesday, March 29, 2017 8:57:35 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/29/2017(UTC)
Posts: 1
Location: United Kingdom

Thanks: 1 times
When running the following test

Code:

public class Class1
{
	[Test]
	public void Test_Fail()
	{
		if (DateTime.Now < DateTime.MinValue)
		{
			// never hit
			var myString = "cow";
			Console.WriteLine(myString);
		}
		else
		{
			var myString = "sheep";
			Console.WriteLine(myString);
		}
	}
}


If setting a breakpoint on the second Console.WriteLine and hovering over myString it shows as null. As does printing in the immediate window. This seems to be related to the scope and the fact that its named the same as the variable in the block above.


Screenshot


This is using Visual Studio 2015, .NET 4.6.2 with the ncrunch plugin 3.3.0.6. I've tried updating to the latest version of ncrunch and this exhibits the same result.
Remco
#2 Posted : Wednesday, March 29, 2017 11:32:50 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi,

Thanks for sharing this problem.

This is a known issue. It's been around for a very long time, and though it's well understood what causes it and even what can be done to fix it, at the moment the better option seems to be not to fix it. I'll try to explain why ...

When NCrunch instruments your assembly for code coverage, it needs to reconstruct the PDB file for this assembly from scratch. This is because all the metadata in the PDB needs to be kept in alignment with the instrumented assembly. Presently, this can only be done using Microsoft's unmanaged symbol writer system that is built into the O/S. This component is very old and it does have some limitations; particularly, it doesn't perform as well as I would like it to.

Inside the PDB, each method (with its local variables) is represented as a series of scopes (basically the {} in C#). Each scope has its own independent variable declarations, which is what allows languages like C# to have the behaviour you've shown above, with two different variables sharing the same name.

The problem is that the MS unmanaged symbol writer can only be fed instructions one scope at a time. This action is fairly expensive (in relative terms), so it's in our interests to use it as little as possible. For this reason, NCrunch actually 'flattens' the scopes for each method into a single scope that contains all instructions. The net effect of this is greatly improved performance at the cost of some strange debug behaviour when examining variables that share the same name.

So basically, it wouldn't be possible to fix this without a noticeable reduction in instrumentation performance .. which means more time waiting for builds to run.

There may be other models that can solve this problem at the cost of greater complexity, and there are also some opportunities on the horizon. For example, the unmanaged symbol writer is now open source, so it's finally possible for us to write our own symbol writers that perform much better. Unfortunately this all involves an investment of time and effort to solve a problem that is a relatively low priority compared to many of the newer issues related to other changes into the ecosystem (i.e. .NET Core, VS2017, CPS, etc). So I don't think we'll see a solution to this in the near future.
1 user thanked Remco for this useful post.
benjohnston on 3/29/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.035 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download