Tutorial: Debug a Service Fabric Mesh application running in your local development cluster


The preview of Azure Service Fabric Mesh has been retired. New deployments will no longer be permitted through the Service Fabric Mesh API. Support for existing deployments will continue through April 28, 2021.

For details, see Azure Service Fabric Mesh Preview Retirement.

This tutorial is part two of a series and shows you how to build and debug an Azure Service Fabric Mesh app on your local development cluster.

In this tutorial you'll learn:

  • What happens when you build an Azure Service Fabric Mesh application
  • How to set a breakpoint to observe a service-to-service call

In this tutorial series you learn how to:

Service Fabric Mesh is currently in preview. Previews are made available to you on the condition that you agree to the supplemental terms of use. Some aspects of this feature may change prior to general availability (GA).


Before you begin this tutorial:

Download the to-do sample application

If you didn't create the to-do sample application in part one of this tutorial series, you can download it. In a command window, run the following command to clone the sample app repository to your local machine.

git clone https://github.com/azure-samples/service-fabric-mesh

The application is under the src\todolistapp directory.

Build and debug on your local cluster

A Docker image is automatically built and deployed to your local cluster as soon as your project loads. This process may take a while. To monitor the progress in the Visual Studio Output pane, set the Output pane Show output from: drop down to Service Fabric Tools.

Press F5 to compile and run your service locally. When the project is run and debugged locally, Visual Studio will:

  • Make sure that Docker for Windows is running and set to use Windows as the container operating system.
  • Download any missing Docker base images. This part may take some time
  • Build (or rebuild) the Docker image used to host your code project.
  • Deploy and run the container on the local Service Fabric development cluster.
  • Run your services and hit any breakpoints you have set.

After the local deployment is finished, and Visual Studio is running your app, a browser window will open to a default sample web page.

Debugging tips

Make your first debugging run (F5) much faster by following the instructions in Optimize Visual Studio performance.

There's currently an issue that causes the call to using (HttpResponseMessage response = client.GetAsync("").GetAwaiter().GetResult()) to fail connect to the service. This can happen whenever your host IP address changes. To resolve this:

  1. Remove the app from the local cluster (in Visual Studio, Build > Clean Solution).
  2. From the Service Fabric Local Cluster Manager, select Stop Local CLuster, and then Start Local Cluster.
  3. Redeploy the app (in Visual Studio, F5).

If you get the No Service Fabric local cluster is running error, make sure that the Service Fabric Local Custer Manager (LCM) is running and right-click the LCM icon in the task bar, then click Start Local Cluster. Once it has started, return to Visual Studio and press F5.

If you get a 404 error when the app starts, it could mean that your environment variables in service.yaml are incorrect. Make sure that ApiHostPort and ToDoServiceName are set correctly per the instructions in Create environment variables.

If you get build errors in service.yaml, make sure that spaces, not tabs, are used to indent the lines. Also, for now, you must build the app using the English locale.

Debug in Visual Studio

When you debug a Service Fabric Mesh application in Visual Studio, you're using a local Service Fabric development cluster. To see how to-do items are retrieved from the back-end service, debug into the OnGet() method.

  1. In the WebFrontEnd project, open Pages > Index.cshtml > Index.cshtml.cs and set a breakpoint in the OnGet method (line 17).
  2. In the ToDoService project, open TodoController.cs and set a breakpoint in the Get method (line 15).
  3. Go back to the browser and refresh the page. You hit the breakpoint in the web front-end OnGet() method. You can inspect the backendUrl variable to see how the environment variables that you defined in the service.yaml file are combined into the URL used to contact the back-end service.
  4. Step over (F10) the client.GetAsync(backendUrl).GetAwaiter().GetResult()) call and you'll hit the controller's Get() breakpoint. In this method, you can see how the list of to-do items is retrieved from the in-memory list.
  5. When you're done, stop debugging your project in Visual Studio by pressing Shift+F5.

Next steps

In this part of the tutorial, you learned:

  • What happens when you build an Azure Service Fabric Mesh application
  • How to set a breakpoint to observe a service-to-service call

Advance to the next tutorial: