How To Fix XML Comment Warning In ASP.NET Web API

While working with swagger documentation in an API we have to enabled the XML file to be generated for documentation from project setting and due to this reason all the pubic members in the project solution start giving the warnings "CS1591 Missing XML comment for publicly visible type or member" and if we specify the XML comment for those members then the same warning will be get disappeared but what for those members which are not a part of swagger documentation, If we ignore then their will be lots of warnings in the code which looks very uglier in the code, So in this article we will discuss how to resolve the "CS1591 missing XML comment for publicly visible type or member" warning.



CS1591 Missing XML Comment  Solution

Define XML Comment for All Public Members

As per me the best way is to define the XML comment for all public members whether its part of swagger UI document or not because of comments our method become more meaningful which help new developer to know about the method by comments instead of going through the code & understand the logic.




Another Advantage for defining the XML comment is, when developer implementing the any method in another class its show's the IntelliSense about the method which help developer to know what is the functionality of method without navigating to the method defined class.

Suppress Warning by Decorating each Public Member

Even though first approach has lots of advantages but you don't want to invest lots of time & increase the size of the project we can suppress the each public member by decorating with following line
#pragma warning disable CS1591


If you don't know the syntax then simply follow the visual studio suggestion by keeping the mouse on specific method or member






Suppress all Warnings at Project Level

The previous two approaches requires lots of time either defining the XML comment or  disabling the warning of each member in project.

To save the time & minimize the swagger comment related warnings we can disable these warning at project level itself with the just one line configuration, to achieve follows the following steps
Right click on api project solution & find the properties 


or just use Alt + Enter by putting control of project solution which opens the following window, find the options by following the below image & enter the 1591 in the suppress warnings text box & save it.



Now check any class file, you will not be see any warnings related to the swagger XML comment


Summary

Hope this article helped you to fix Warning CS1591 Missing XML comment for publicly visible type or member. If you like the contents the support by using the following way.

Related Articles

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode