Search

VS2012 debugger shows null after a null-coalescing has executed even tho it should not be null. by DaveHanson

Active

4
0
Sign in
to vote
Type: Bug
ID: 779141
Opened: 2/13/2013 7:48:21 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Visual studio when using a null-coalescing operator shows a null value for an object when debugging. I have looked into this issue and it seems to be the fact that the null-coalescing operator result is being inlined as function parameter via the compiler.


Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

Microsoft Visual Studio Professional 2012
Version 11.0.51106.01 Update 1
Microsoft .NET Framework
Version 4.5.50709

Make sure the project is targetting .net 4.0

In the "TestMethod" look at the value after the coalescing operator has executed. You will see it says null. Debug into the InternalMethod and you will see the value has been produced.

    public class Foo
    {
        private IEnumerable<Bar> _items;

        public Foo()
        {
            _items = new List<Bar>()
                {
                    new Bar(),
                    new Bar(),
                    new Bar(),
                    new Bar(),
                    new Bar(),
                    new Bar(),
                    new Bar() { Type = "Default" }
                };
        }


        public void TestMethod()
        {
            var value = _items.FirstOrDefault(s => s.Type.Equals("Johnny")) ?? _items.FirstOrDefault(s => s.Type.Equals("Default"));
            InternalMethod(value);
        }

        private void InternalMethod(Bar value)
        {
            Console.WriteLine(value);
        }
    }

    public class Bar
    {
        public Bar()
        {
            Type = Guid.NewGuid().ToString();
        }

        public string Type { get; set; }
    }

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Debugger shows null for the value after the coalescing operator has run

Expected results

The debugger should show the value.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/6/2013 at 2:21 PM
Hi,

I'm closing this issue as there hasn't been another response. Thanks again for your feedback!

Kind Regards,
Dustin Campbell
Visual Studio Managed Languages
Posted by Microsoft on 4/22/2013 at 8:31 AM
Hi,

Thanks for contacting us about this issue. We are able to repro the problem that you described on Visual Studio 2012, but it appears to be working on recent internal builds. We believe this should work correctly for you in the next release of Visual Studio.

Kind Regards,
Dustin Campbell
Visual Studio Managed Languages
Posted by Microsoft on 2/13/2013 at 10:35 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/13/2013 at 7:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.