This is the eighth of a new series of posts on ASP .NET Core. In this post, we’ll learn how to use the .NET CLI file watcher tool during development and debugging.
Before You Begin
Before you begin, take a look at the sample code project on GitHub:
AspNetCoreWatcher on GitHub: https://github.com/shahedc/AspNetCoreWatcher
Specifically, look at the history of CalcController to see how the Sum() method has been updated to accept doubles and not just ints, when summing up two numbers.
- Github link: before the change
- Github link: after the change
Debugging while Running
Initially, we have a Sum() method that looks like this:
[Route("[action]")] public ActionResult<string> Sum( [FromQuery(Name = "num1")] int num1, [FromQuery(Name = "num2")] int num2) { var sum = (num1 + num2).ToString(); return $"The sum of numbers {num1} and {num2} is {sum}."; }
We can run the web app from the command line using dotnet run:
> dotnet run
This allows us to access the Web API via a web browser to add 2 numbers, e.g. 3 and 4 for num1 and num2.
https://localhost:5001/api/calc/Sum?num1=3&num2=4
However, we get an error if we try to pass in numbers with decimal points, e.g. 3 and 4.4 for num1 and num2.
https://localhost:5001/api/calc/Sum?num1=3&num2=4.4