I am getting this warning: "Missing XML comment for publicly visible type or member".
How to solve this?
I am getting this warning: "Missing XML comment for publicly visible type or member".
How to solve this?
5 options:
#pragma warning disable 1591 to disable the warning just for some bits of code (and #pragma warning restore 1591 afterwards)Add XML comments to the publicly visible types and members of course :)
///<Summary>
/// Gets the answer
///</Summary>
public int MyMethod()
{
return 42;
}
You need these <summary> type comments on all members - these also show up in the intellisense popup menu.
The reason you get this warning is because you've set your project to output documentation xml file (in the project settings). This is useful for class libraries (.dll assemblies) which means users of your .dll are getting intellisense documentation for your API right there in visual studio.
I recommend you get yourself a copy of the GhostDoc Visual Studio AddIn.. Makes documenting much easier.
Insert an XML comment. ;-)
/// <summary>
/// Describe your member here.
/// </summary>
public string Something
{
get;
set;
}
This may appear like a joke at the first glance, but it may actually be useful. For me it turned out to be helpful to think about what methods do even for private methods (unless really trivial, of course).
A really simple way to suppress the warning is to add a property in the .csproj file:
<Project>
<PropertyGroup>
...
<!--disable missing comment warning-->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
...
Setting the warning level to 2 suppresses this messages. Don't know if it's the best solution as it also suppresses useful warnings.
Late in here but many solutions in this thread focus on removing the warnings entirely within the project or within the class.
If you want to keep the legitimate warnings but remove some - e.g. the cancellationToken on a WebApi controller when you expose the API using swagger (the api user does not need this - it is supplied by DI).
Ugly and obvious but at least in this case cancellation tokens are the last param.
/// <summary>
/// Creates a Service
/// </summary>
/// <param name="service">The Service Definition</param> (**note no cancellation token param**)
/// <returns>A newly created item</returns>
/// <response code="201">Returns the newly created service</response>
/// <response code="400">If there are validation errors with the submitted json body</response>
/// <response code="409">Conflict. The service already exists</response>
/// <response code="500">Because life is never perfect</response>
[ProducesResponseType(typeof(Service), 201)]
[ProducesResponseType(400)]
[ProducesResponseType(409)]
[ProducesResponseType(500)]
[HttpPost]
public async Task<ActionResult> ServiceCreate([FromBody] ServicePostRequest service,
#pragma warning disable 1573
CancellationToken cancellationToken = default) //**note: no warning**
#pragma warning restore 1573
{
The answer from @JonSkeet is almost complete. If you want to disable it for every project in your solution you could add the row below to a .editorconfig file.
dotnet_diagnostic.CS1591.severity = none
https://github.com/dotnet/roslyn/issues/41171#issuecomment-577811906
https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022
See file hierarchy and precedence on where to add the file:
I got that message after attached an attribute to a method
[webMethod]
public void DoSomething()
{
}
But the correct way was this:
[webMethod()] // Note the Parentheses 
public void DoSomething()
{
}