I don’t want to write comments or run code coverage on autogenerated code

The “warning CS1591: Missing XML comment for publicly visible type or member” issue

You’ve created a WCF service proxy and you’ve XML documentation turned on like the picture shows below.


Then you most likely will have a lot of warnings the next time you build your project like so:


Don’t despair the solution is close.


Find the Reference.cs file if you added a Service Reference manually or if you auto generated the Service Reference using the “svcutil.exe” utility open up the generated class.

Add the following line of code in your namespace:

#pragma warning disable 1591 //Disables CS1591 Warning


Auto generated code has lousy Code Coverage

Then you’ll be left with the issue that your auto generated code has lousy Code Coverage, if you haven’t written any tests against it that is. The question if you should write tests on auto generated code or not I leave it up to you. I’ll leave at that with the cowardly answer “it depends” Ler The before picture might look like this:


Notice how the auto generated namespaces are listed in Code Coverage.


This is as easily fixed as the XML Warning. In the file where you have the auto generated code use search and replace to add the


attribute to every class.


Finish things off with a Edit->Advanced->Format Document to get a nice formatting and your good to go!


Try compiling and watch as your code coverage goes up!




2 Replies to “I don’t want to write comments or run code coverage on autogenerated code”

  1. There is a slight problem with your solution to the code coverage problem in reference.cs.
    Everytime you update your service reference your addition of [ExcludeFromCodeCoverage] will be gone.
    To solve that problem I have a new solution for you.
    Given the fact that all classes in reference.cs are implemented as partial, you can basically add a new class file that implements the same classes that is included in your reference.cs. In your new file you add [ExcludeFromCodeCoverage] on each class.
    Now you can update your service reference without worrying about code coverage.

Leave a Reply to Öystein Stave Cancel reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.