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

Build and Run ASP.NET Core Application in Docker Container

In this article we will learn how to build and run ASP.NET core application in a docker container. The docker and containerization term is booming in the market and developer and IT professional curious to know and learn about the docker and containerization but due to lack of plain simple documentation people finds hard to understand about these terms and concepts, my intend to write this article is to clear the hype around these concepts and make understandable to everyone by explaining in the plain simple language.

Hype around the Docker Learning

Many documentation, articles and YouTube videos show lots of command line tools during building the docker application and often readers think that I need to learn these commands and due to this, they find it very difficult and complex to create the docker application but believe me you don't need all to remind and know the commands. Visual studio built in features for azure containers makes it very simple for you. You can first learn the docker concepts using the way which I am showing in this article, then once you are familiar with these terms and concepts, you can use advanced tools such as docker commands etc.

What is Docker?

Docker is the platform for deploying and building the applications which delivers the application in the packages over the operating system level virtualization. Docker requires the following components to run the application

  • Image 
  • Container

What is docker image?

Docker image is the set of configuration and instructions to create the docker container, an image is created during building the application based on steps defined in the docker file of your application. The docker image is the read-only file which cannot be modified once it's created, but we can delete the image from docker.

What is Container?

The Container is an independent isolated process of an operating system which has its own networking and file system to run the image or application. The container is created on the docker engine based on the image configuration.

What is difference between Virtual Machine and Docker Container?

The virtual machine (Linux, ubuntu) is installed on some other operating system (windows) which shares the same lifecycle such as running and shutting at the same time. Virtual machine acts as a real PC on an actual operating system which has full features such as RAM, Hard Disk, networking etc. In this case, often virtual machines are called guest PC and the actual PC which runs the VM is called host system machine.

The container is the minimal and smaller part of a virtual machine which does not use the entire operating system as a virtual machine. The container cuts the unnecessary components of the VM and creates the isolated virtualized environment called a container, which is faster than virtual machine. The container does not require the host system as a virtual machine instead, it works on the docker engine.

The preceding diagram gives more understanding about the virtual machine and docker container, now let's start building and running the ASP.NET Core application in docker step by step.

Step 1: Install Prerequisites

You need to install the docker desktop client based on your machine (PC) as per your operating system type. Use the following link to download the docker desktop client.
The installed docker desktop client looks like as follows.


I hope you installed the prerequisites.

Step 2 : Create the ASP.NET Core Application

  1. Open Visual Studio (I am using 2019)
  2. Once Visual studio open then click on continue without code(If you are using VS 2019)
  3. Then from Visual Studio Menu, click on File => New Project , as shown in the following image

After clicking on the New Project, following window will get appears, Choose the project template ASP.NET Core Web App as shown in the following image


After Choosing the project template click on next button, provide the project name and storage location of the project on your PC


After providing the required details, click on next button the following screen will get appears. Provide the additional information for your project such as target framework and other details, Just choose the latest .NET 5.0 and skip other details

 
Now providing the required details, click on create button it will create the ASP.NET Core web application and created ASP.NET Core web application looks like as follows in your visual studio.

Step 3: Add Docker Support

Docker support can be enabled in two ways from visual studio, at the time of creating the application and after creating the application. To make it easier to make understand for beginners, in this tutorial we will enable the docker support after creating the ASP.NET core application.
Right click on the solution explorer of your existing project and follow the steps which are shown in the following image.


Once you click on the Docker Support option, it will prompt the screen which is shown in the step 4.

Step 4: Choose the Container (Docker File)

Choose the target operating system on which type of container you want to run the application, and it will create the docker image. Let's choose the Linux option which creates the image size smaller than compared to the windows container image.


In the preceding image click on the OK button, it will create the Docker file in your project solution as shown in the following image.


Step 5: Open the Docker File

Double click on docker file in which you will see auto generated code from visual studio which has pre-configured steps to create and run the docker image in multiple stages.

The visual studio creates docker file in your project which has multi-stages build features which make sure the final image remain smaller in the size which helps to become container more efficient and faster. The container images created in the following stages
  • Base 
  • Build 
  • Publish
  • Final Image

We will learn more about the base image and docker file stages in a separate article.

Step 6:  Run the image in Docker Container

Choose the docker option to run the application as shown in the following image.


After clicking on the docker option, it will build code, create a docker image as well as a docker container and run the application inside the docker container without using the docker commands on the windows command prompt. The application opens the browser as follows.


In the preceding, our application is running inside the Linux Docker container instead of IIS express. We can view the created images by using the docker command or navigating to the docker desktop dashboard. Let's view images using the docker command. Open your windows command prompt and use the following command on the command prompt and press enter.

           Docker Images

The preceding docker command will display the list of available docker images as follows.


I hope from all the above-mentioned examples you have learned how to build and run the asp.net core application inside the docker container.

Note

  • This tutorial is for the beginner, so there is no command line tool used to build, run the docker container images. 
  • The intend of this tutorial is to make familiar to beginners about docker.
  • Next article we will learn how to build, run and create images using docker commands.

Summary

I hope the preceding article is useful to understand how to build and run ASP.NET core application in a docker container. You can support me by subscribing to my YouTube Channel and blog by using the following links.
Related articles

How To Add Docker Support For Existing ASP.NET Project

In this article we will learn how to add docker support for existing ASP.NET  or any .NET application, before enabling docker support let's know about the docker in brief

What is Docker?

Docker is one of the platform for containerizing the applications which allows to deliver the application in packages over the operating machine level virtualization. Docker allows to run and create the images in Linux and windows containers etc.

Step 1: Install Prerequisites

You need to install the docker client based on your operating system on your machine. you can download the docker by using the following link

The installed docker desktop client will be look like as shown in the following image, 


Hope you installed the prerequisites.

Step 2: Open Existing Application

Open your existing application in visual studio as shown in the following image


Docker client helps to create and run the docker images locally as well as created images you can push in to the any image container registry such as ACR or docker hub.

Step 3: Add Docker Support

Now right click on the solution explorer of your existing project and follows the steps which are shown in the following image


Once you click on the Docker Support option , It will prompt the screen which is shown in the step 4.

Step 4: Choose the Container

Choose the target operating system on which type of container you wants to run the application. Let's choose the Linux option which creates the image size smaller than windows container image.


In the preceding image click on the OK button, it will create the Docker file in your project solution as shown in the following image



Step 5: Open the Docker File

Now double click on docker file, it has following auto generated code from visual studio which has pre-configured steps to create and run the docker image 


Step 6:  Run the image in Docker Container

Choose the docker option to run the application as shown in the following image


After clicking on docker option, application runs inside the docker container as shown in the following image
 

Now our application running inside the Docker container instead of IIS express.

Note

This tutorial is for beginner so there is no command line tool used to build , run the docker container images in this tutorial. The intend of this tutorial to make familiar to beginners about docker and let them know docker is not difficult to learn.

Summary

I hope the preceding article is useful to understand how to enable the docker support for existing ASP.NET project with less efforts.

If you like my efforts and intend then support me by subscribing my YouTube Channel and blog by using the following links

CS1591 Missing XML Comment for Publicly Visible Type or Member

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 discus 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.

Get Data in ASP.NET MVC Using Web API

This article  explains step by step how to get data in ASP.NET MVC using web api. To demonstrate this lets create simple ASP.NET MVC application before it if you are new and wants to learn web API REST service from creating to hosting to consuming in client application.
In this article, we will use the same hosted Web API REST service  to consume in our created ASP.NET MVC web application. Now, let's start consuming Web API REST service in ASP.NET MVC application step by step.

Step 1 - Create ASP.NET MVC Application.

  1. "Start", followed by "All Programs" and select "Microsoft Visual Studio".
  2. Click "File", followed by "New" and click "Project". Select "ASP.NET Web Application Template", provide the Project a name as you wish and click OK.
  3. After clicking, the following Window will appear. Choose empty project template and check on MVC option.

The preceding step creates the simple empty ASP.NET MVC application without model, view, and controller, the solution explorer of created web application will look like the following.


Step 2 - Install HttpClient library from NuGet

We are going to use HttpClient to consume the web api, so we need to install this library from nuget package manager

What is HttpClient ?

HttpClient is base class which is responsible to send HTTP request and receive HTTP response resources i.e from REST services.

To install HttpClient, right click on Solution Explorer of created application and search for HttpClient, as shown in the following image.


Step 3 - Install WebAPI.Client library from NuGet

This package is used for formatting and content negotiation which provides support for System.Net.Http. To install, right click on Solution Explorer of created application and search for WebAPI.Client, as shown in following image.



Now, click on "Install" button after choosing the appropriate version. It will get installed after taking few seconds depending on your internet speed. We have installed necessary NuGet packages to consume Web API REST services in web application. I hope you have followed the same steps.

Step 4 - Create Model Class 

Now, let us create the model class named Employee.cs  or as you wish, by right clicking on models folder with same number of entities which are exposing by our hosted Web API REST service to exchange the data. The code snippet of created Employee.cs class will look like as follows

    public class Employee  
    {  
        public int Id { get; set; }  
        public string Name { get; set; }  
                 
        public string City { get; set; }  
      
    }   

Step 5 - Add Controller Class

Now, let us add ASP.NET MVC controller, as shown in the screenshot given below.


After clicking add button, it will show in the window. specify the controller name as Home with suffix controller. Now, let's modify the default code of  Home controller . Our hosted Web API REST Service includes these two methods, as given below.
  • GetAllEmployees (GET )
  • GetEmployeeById (POST ) which takes id as input parameter 
The url of the hosted web API REST Service is 

http://192.168.95.1:5555/api/Employee/GetAllEmployees

In the preceding url
  • http://localhost:56290 Is the base address of web API service, It can be different as per your server
  • api It is the used to differentiate between Web API controller and MVC controller request
  • Employee This is the Web API controller name
  • GetAllEmployees This is the Web API method which returns the all employee list
After modifying the code of Homecontroller class, the code will look like the following.

Homecontroller.cs
using ConsumingWebAapiRESTinMVC.Models;  
using Newtonsoft.Json;  
using System;  
using System.Collections.Generic;  
using System.Net.Http;  
using System.Net.Http.Headers;  
using System.Threading.Tasks;  
using System.Web.Mvc;  
  
namespace ConsumingWebAapiRESTinMVC.Controllers  
{  
    public class HomeController : Controller  
    {  
        //Hosted web API REST Service base url  
        string Baseurl = "http://192.168.95.1:5555/";      
        public async Task<ActionResult> Index()  
        {  
            List<Employee> EmpInfo = new List<Employee>();  
              
            using (var client = new HttpClient())  
            {  
                //Passing service base url  
                client.BaseAddress = new Uri(Baseurl);  
  
                client.DefaultRequestHeaders.Clear();  
                //Define request data format  
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
                  
                //Sending request to find web api REST service resource GetAllEmployees using HttpClient  
                HttpResponseMessage Res = await client.GetAsync("api/Employee/GetAllEmployees");  
  
                //Checking the response is successful or not which is sent using HttpClient  
                if (Res.IsSuccessStatusCode)  
                {  
                    //Storing the response details recieved from web api   
                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;  
  
                    //Deserializing the response recieved from web api and storing into the Employee list  
                    EmpInfo = JsonConvert.DeserializeObject<List<Employee>>(EmpResponse);  
  
                }  
                //returning the employee list to view  
                return View(EmpInfo);  
            }  
        }  
    }  
}  

I hope, you have gone through the same steps and understood about the how to use and call Web API REST service resource using HttpClient .

Step 6 - Create strongly typed View

Now, right click on Views folder of the created application and create strongly typed View named by Index by choosing Employee class to display the employee list from hosted web API REST Service, as shown in the following image.


Now, click on "Add" button. It will create View named index after modifying the default code. The code snippet of the Index View looks like the following.

Index.cshtml 
@model IEnumerable<ConsumingWebAapiRESTinMVC.Models.Employee>  
  
@{  
    ViewBag.Title = "www.compilemode.com";  
}  
  
<div class="form-horizontal">  
  
    <hr />  
    <div class="form-group">  
  
  
        <table class="table table-responsive" style="width:400px">  
            <tr>  
                <th>  
                    @Html.DisplayNameFor(model => model.Name)  
                </th>  
                <th>  
                    @Html.DisplayNameFor(model => model.City)  
                </th>  
                  
            </tr>  
  
            @foreach (var item in Model) {  
                <tr>  
                    <td>  
                        @Html.DisplayFor(modelItem => item.Name)  
                    </td>  
                    <td>  
                        @Html.DisplayFor(modelItem => item.City)  
                    </td>  
                      
                </tr>  
}  
  
        </table>  
    </div>  
</div>  

The preceding View will display all employees list . Now, we have done all the coding.


Step 7 - Run the Application

After running the application, the employee list from hosted web api REST service will look like this.



I hope, from the above examples, you have learned how get data in ASP.NET MVC using web api

Note
  • In this article, the optimization is not covered in depth; do it as per your skills.
Summary

I hope, this article is useful for all the readers to learn about getting data from web api in ASP.NET MVC. If you have any suggestions, please contact me. 

Fix Missing XML comment for Publicly Visible Type or Member

While working with swagger documentation in an API, we have to enable the XML file to be generated for documentation from the project setting. For this reason, all the public members in the project solution start giving the warning "CS1591: Missing XML comment for publicly visible type or member" 

we can simply define the XML comment for those members, and the same warning will disappear. But what about those members who are not a part of the swagger documentation? If we ignore them, then there will be lots of warnings in the code, which looks very ugly in the code.

In this article we will discuss how to resolve the "CS1591 missing XML comment for publicly visible type or member" warning by using one of three different solutions.

  • Create an XML Comment for All Public Members 
  • Disable Warning by Decorating Each Public Member
  • Disable all warnings at the project level. (Recommended)



Define XML Comment for All Public Members

The best way is to define the XML comment for all public members, whether it is part of the swagger UI document or not. Because of comments, our method becomes more meaningful, which helps new developers learn about the method by comments instead of going through the code and understanding the logic.




Another advantage of defining the XML comment is that when a developer implements any method in another class, it shows the IntelliSense about the method, which helps the developer to know what the functionality of the method is without navigating to the method defined class.

Suppress Warning by Decorating each Public Member

Even though the first approach has lots of advantages but it requires lots of time and it will increase the size of the project .

The alternate solution to the preceding mentioned problem is  we can suppress each public member by decorating with the following line, which does not require you to provide the XML comment.

#pragma warning disable CS1591


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









Suppress all Warnings at Project Level

The previous two approaches necessitate a significant amount of time spent either defining the XML comment or disabling the warning for each project member.

To save time and minimise the swagger comment related warnings, we can disable these warnings at the project level itself with just one line of configuration. To achieve this, follow the following steps:
 
Right-click on the 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 see any warnings related to the swagger XML comment.


Summary

I hope this article helped you to fix Warning CS1591: Missing XML comment for publicly visible type or member.

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode