Search

Generated code uses DebuggerNonUserCode attribute improperly for Properties by eradicator1

Closed
as Fixed Help for as Fixed

6
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 338895
Opened: 4/18/2008 10:00:20 AM
Access Restriction: Public
0
Workaround(s)
2
User(s) can reproduce this bug
When VS 2005 or 2008 generates code (for example, a DataSet generated from a .xsd schema, or when generating the Settings.Designer.cs file), it adds code like the below on generated property members:

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
// ... other attributes not shown as they are not relevant to the discussion
public string Foo {
    get {
     return this.foo;
    }
}

Presumably one reason for adding the DebuggerNonUserCode attribute is to exclude the members from code coverage (as that is the only workaround currently, since there is nothing like an [ExcludeCoverage] attribute (P.S. Wouldn't it be great if there were?)

However, code coverage ignores that attribute for properties unless it is applied specifically to the getter (and/or setter) like this:

public string Foo {
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] // apply to getter
    get {
     return this.foo;
    }
    // if there were a setter, we'd also need it here
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] // apply to setter
    set {
     // do something cool
    }
}

Actually, for 2008 it should have just applied the attribute to the whole class like this:
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
// no need to apply the attribute to any members here
}

(For VS2005 the attribute can be applied to the class, but it is ignored anyway! But VS2008 code coverage seems to take it)

1) Please fix code coverage to pick up the attribute correctly
2) Please fix code generator to place the attribute correctly
3) Better yet, please provide something like an [ExcludeCoverage] attribute to be used by the code coverage system, and make the code generator(s) apply it as well
Details (expand)
Product Language
English

Version

Visual Studio 2008 (All Products and Editions)
Operating System
Windows Vista
Operating System Language
English
Steps to Reproduce
Create a VS 2008 project and create Settings for it. Add one or more dummy application-level properties. A Settings.settings file is created, and VS generates a Settings.Designer.cs file (among other files).

Create a MSTest unit test project to exercise the first project, but don't exercise any code in the Settings class.

Run the unit test, and view code coverage. Notice how it shows you didn't cover the Settings code, in particular the "get_SomeProperty" methods it shows to represent the property getters -- regardless of the fact that they were supposedly to be excluded from coverage by virtue of the DebuggerNonUserCode attribute applied.

I could provide an attachment solution (*.sln) and projects if need be, but I want to at least see that I'm not wasting my time opening this bug (as in, is anyone at MS really going to notice it?)
Actual Results
Code coverage included code we don't want covered
Expected Results
Expect code coverage to exclude the code with the attribute applied
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 4/21/2008 at 1:40 AM
Thanks for your feedback. We are escalating 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.

Thank you,
Visual Studio Product Team
Posted by eradicator1 on 4/30/2008 at 10:48 AM
I don't understand why this is now marked as "Resolved" and "Closed". Nobody has followed up other than the "thanks for your feedback..." comment, followed by closing it. So you're going to fix it in a future version, or what?
Posted by Microsoft on 5/9/2008 at 5:30 PM
Not to worry this is just a process glitch, we recently upgraded to a new server for connect issues and unfortunately during the migration a lot of issues were closed that should not have been. We are in the process of fixing that but its going to take a few days.

Regards,

Euan Garden (euan.garden@microsoft.com)
Posted by Microsoft on 1/23/2009 at 2:11 PM
Hello eradicator1,

Thank you for taking the time and reporting the problem to us. We have been able to reproduce the error and actively working towards a solution. I apologize for any inconvenience this issue may have caused you.

We value your feedback and suggestion, so please feel free to contact us via MS Connect channel, or contact me directly at dalaqab@microsoft.com.

Regards,
Daryush Laqab
Program Manager
VSTS Profiler and Code Coverage
Posted by Microsoft on 3/3/2009 at 10:41 AM
We have fixed this issue to respect DebuggerNonUserCode and DebuggerHidden at the property level in addition to the class or method level. Please look for this fix in the upcoming release of Visual Studio 2010.

Thank you.
Posted by eradicator1 on 3/3/2009 at 11:54 AM
Glad to hear it will be addressed. Thank you