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

Notification

Icon
Error

Extension Methods in Watch window
SchlaWiener
#1 Posted : Tuesday, July 15, 2014 2:19:04 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/18/2014(UTC)
Posts: 2
Location: Germany

Consider the following test

Code:

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var items = new List<string> { "Dog", "Cat" };
            var item = items.First();

            Assert.AreEqual("Dog", item);
        }


Now, if I debug the Test with Visual Studio I can use Enumerable.Extensions like First() but with NCrunch I can not. This makes it sometimes very hard to debug ncrunch tests.
A great blog post why this is possible with Visual Studio can be found here. http://blogs.msdn.com/b/...s-and-the-debugger.aspx


With MSTest


With NCrunch


If I understand the blog post right, it would be possible to achive this, If NCrunch would preload System.Core into it's debugger process. Is there a way to do this. I even tried the "Pre-load all assembly references into test environment" but it didn't help.

On a side note: Extension Methods within the same project seem to work. If I add

Code:
    
public static class ExtensionMethods
    {
        public static T First2<T>(this IEnumerable<T> source)
        {
            return source.First();
        }
    }


to the project I can use items.First2() in the debugger.

I use
- Visual Studio 2010 Profession
- Windows 8.1 x64
- NCrunch 2 (latest)
Remco
#2 Posted : Tuesday, July 15, 2014 10:00:28 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi,

Thanks for sharing this and for taking the time to explain it in detail.

There is more going on here than just the need to load System.Core.dll into the process - although I can understand why preloading this DLL might make a difference in resolving the extension method. The problem for NCrunch is deeper and actually much more serious.

Each method written to a DLL by the C# compiler is associated with debug metadata written to a PDB file. This metadata includes information such as local variable names, iterator data (i.e. delegates to virtual classes constructed by the compiler) and namespace usage data. When you debug your code, the VS debugger extracts this metadata from the PDB and uses it to make sense of the debug context.

In all presently released versions of NCrunch, there is a known problem where this debug metadata is not being correctly rewritten when NCrunch instruments assemblies prior to running tests. This means that when you debug your method under NCrunch, the metadata simply isn't there. The debugger won't know about the First() method because it doesn't know where to find it.

The metadata itself is in an undocumented MS format that isn't clearly formed by any of the available debug APIs. This is why it has been impossible to preserve it or write it back to the PDB. PDB files themselves are based on a very old format controlled by internal windows component that is generally a horrible nightmare to work with.

However, the release of Roslyn's source code has put new light over the structure of the metadata and I'm happy to say that the next release of NCrunch will include some fixes in this area. It still remains to be see how the fixes will perform (the windows symbol writer has a mind of its own), but I'm hopeful that you will see an improvement in issues such as this with the release of NCrunch v2.8.

Cheers,

Remco
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.044 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download