How to Debug and Step Into Service Fabric SDK Source Code

Developer Support

In this blog, Premier Consultant Kurt Schenk shows how to debug into the source code of the Service Fabric SDK which is used to develop Reliable Services and Reliable Actors. Service Fabric is open source, including the SDK which is on GitHub here.


#1. Determine what commit to check out of GitHub

You need to match the source code that you check out with the NuGet package that you are referencing. For example, using Visual Studio we can see that my service is referencing these Service Fabric NuGet packages.

Machine generated alternative text: Microsoft.ServiceFabric by Microsoft This package contains the reference assemblies required to build a Service Fabric service. Microsoft.ServiceFabric.Actors by Microsoft This package contains the common Actor Framework APIs for building and connecting to reliable services on Microsoft Service Fabric. Microsoft.ServiceFabric.Data by Microsoft This package contains the runtime assemblies required by Service Fabric's ReliableCoIIections APIs. Microsoft.ServiceFabric.Data.Extensions by Microsoft This package contains assemblies required by Service Fabric's ReliableCoIIections APIs. Microsoft.ServiceFabric.Data.lnterfaces by Microsoft This package contains the interfaces required by Service Fabric's ReliableCoIIections APIs. Microsoft.ServiceFabric.Diagnostics.lnternal by Microsoft This package provides Diagnostics functionality to be used by Service Fabric Actors and Service framework. This package is intended to be used by other official Microsoft ServiceFabric packages only. Microsoft.ServiceFabric.FabricTransport.lnternal by Microsoft This package provides FabricTransport to be used as the communication mechanism for Service Fabric microservices. This package is intended to be used by other official Microsoft ServiceFabric packages only. Microsoft.ServiceFabric.Services by Microsoft This package contains the common Service Framework APIs for building and connecting to reliable services on Microsoft Service Fabric. Microsoft.ServiceFabric.Services.Remoting by Microsoft This package contains the Service Framework Remoting APIs for building and connecting to reliable services on Microsoft Service Fabric. v6A.6i8 v7.14D9 v3v3.6i8 v3v3.6i8 VI 4.658 v3v3.6i8 v3v3.6i8 v3v3.6i8 v3v3.6i8 v3v3.6i8

This is 6.4 CU6 release of Service Fabric, on May 2nd, 2019, which you can verify by going to https://docs.microsoft.com/en-us/azure/service-fabric/release-notes and clicking on “release notes” in section “Service Fabric 6.4 releases” for May 2, 2019. You will see the following table showing that this release is compatible with Service Fabric .NET SDK (3.3.658) / Microsoft.ServiceFabric (6.4.658)

Machine generated alternative text: Service Fabric Runtime Service Fabric for Windows Server .NET SDK Java SDK Service Fabric PowerShell and CLI Ubuntu Windows Service Fabric Standalone Installer Package Windows .NET SDK Microsoft. ServiceFabric Reliable Services and Reliable Actors ASP.NET Core Service Fabric inte Java for Linux SDK AzureRM PowerShell Module SFCTL Visual Studio Toolin Ecli Toolin 6.4.649.1 6.4658 03.15 207

If you are referencing the latest version (Major.Minor) of a Service Fabric release (6.4, 6.5, 7.0, 7.1, https://docs.microsoft.com/en-us/azure/service-fabric/release-notes ) then you can check out the release branch as shown below. So branch release_3.3 is 6.4 CU7 released May 28, 2019 which is .NET SDK (3.3.664) / Microsoft.ServiceFabric (6.4.664).

Machine generated alternative text: Switch branches/tags Filter branches/tags Branches develop Tags release 3.1 release 3.2 release 3.3 release 3.4 release 4. I rem otingrnesh

If you navigate to https://github.com/microsoft/service-fabric-services-and-actors-dotnet/blob/release_3.3/properties/service_fabric_common.props you will see the same confirmed there.

<NugetPkg_Version_Microsoft_ServiceFabric>6.4.644</NugetPkg_Version_Microsoft_ServiceFabric>

<NugetPkg_Version_Microsoft_ServiceFabric_Diagnostics_Internal>3.3.644</NugetPkg_Version_Microsoft_ServiceFabric_Diagnostics_Internal>

<NugetPkg_Version_Microsoft_ServiceFabric_Data>3.3.644</NugetPkg_Version_Microsoft_ServiceFabric_Data>

<NugetPkg_Version_Microsoft_ServiceFabric_FabricTransport_Internal>3.3.644</NugetPkg_Version_Microsoft_ServiceFabric_FabricTransport_Internal>




<MajorVersion>3</MajorVersion>

<MinorVersion>3</MinorVersion>

<BuildVersion>17</BuildVersion>

<Revision>0</Revision

However, in my sample project I am using a slighter earlier version of the Service Fabric SDK and therefore have to go back a few commits, from 6.4.664 back 6.4.658. To find an exact match, look at AssemblineInformationVersion for one of the Service Fabric SDK assemblies referenced in the service, and match to MajorVersion.MinorVersion.BuildVersion.Revision in service_fabric.common.props. For example, looking at bin\x64\Release\Microsoft.ServiceFabric.Actors.dll with ILSpy, I see AssemblineInformationVersion 3.3.15.0.

[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

[assembly: AssemblyCompany("Microsoft")]

[assembly: AssemblyConfiguration("Release")]

[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")]

[assembly: AssemblyFileVersion("3.3.15.0")]

[assembly: AssemblyInformationalVersion("3.3.15.0")]

[assembly: AssemblyProduct("Microsoft Azure Service Fabric")]

[assembly: AssemblyTitle("Microsoft.ServiceFabric.Actors")]

[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]

[assembly: AssemblyVersion("6.0.0.0")]

Going back a bit in commit history there is a match here: https://github.com/microsoft/service-fabric-services-and-actors-dotnet/blob/fe334251815b33aa3d29f243d0c9a2ae5ea8d8d6/properties/service_fabric_common.props.

Now we can check out commit fe334251815b33aa3d29f243d0c9a2ae5ea8d8d6 and this will be an exact match for the Service Fabric SDK source code.

  • Set the local path for the repo

  • The repo has the latest commit from June 1st, 2020

  • Open command prompt in Git Desktop

  • Checkout commit above

  • We can see we have the version we were looking for in service-fabric-services-and-actors-dotnet\properties\service_fabric_common.props

  • To go go back to the most recent local commit type git checkout develop

Git for Windows (https://gitforwindows.org/) is a great tool that you could use for this as well.

#2. Run code that will execute the code path that you want to test

This will ensure that the that the relevant assemblies have loaded into the process. In my case, I go to http://localhost:8181/api/Actors/1 in my browser, and the ASP.NET Core controller then calls a Service Fabric Actor service using an ActorProxy andService Fabric Remoting. The Actor method throws a custom FabricNotReadableException, MyFabricTransientException(“My custom FabricTransientException”), and after some retries the ActorProxy fails and throws an exception.

Machine generated alternative text: CD O localhost:8181/api/Actors/1 An unhandled exception occurred while processing the request. TaskCanceIedException: A task was canceled. func, CancellationToken cancellationToken, Type0 daNotRetryExceptionTypes) Query Cookies Headers TaskCanceIedException: A task was canceled. func, CancellationTcken cance'IatianTaken, Typec dcNctRetryExceptianTypes: headers, byteC requestVsg3cdy, CancelletianTaken cancelLationToken) interfaceld, int method'd, abject requestVsgBodyVa'ue, CancelletianTaken cancellation Token) id, int deLayMs) in ActorsContr011er. return await Task.

#3 Attach to the service you want to debug

Now attach to the service, which in my case is a Stateless Service called StatlessWebApp2 that has the ASP.NET Core code I want to debug. I am using Visual Studio 2019, with a local development cluster.

Machine generated alternative text: Attach to Process Connection type: Connection target: Default KS800K Find... Connection type information The default connection lets pu select processes on this computer or a remote computer running the Visual Studio Remote Debugger (MSVSMON.EXE). Attach to: Available processes Process Stateless'UebApp2.exe Automatic: Managed (v4.6, v4.5, v4.O) code Tltle web Type Managed User Name NETUORK SERVICE

#4. Load Service Fabric SDK assemblies

You may need to set the symbol path in Visual Studio. To do that go File Menu, to Debug\Options\, then to Debugging\Symbols. And make sure that Microsoft Symbol Servers checkbox is selected. You could add a reference to symbols for your code as well here. If you have set _NT_SYMBOL_PATH environment variable, which I hav, it will show up in the UI here as well.

In order for your breakpoint to be hit, you have to be sure that the Service Fabric SDK symbols are loaded. Since you executed the code path you are interested in (#2), now you can go to Debug/Windows/Modules and load the symbols needed. You will see Symbol Status: Symbols loaded if this successful. Symbols may not be found for some assemblies, like Microsoft.ServiceFabric.Internal.dll, which does not have public symbols.

Machine generated alternative text: Modules Search: fab ric.dll MicrosoftServicZicServices.dII MicrosoftServicZic.InternaI.dII SystemZricStrings.dII MicrosoftServicZic.Diagnostics.dII MicrosoftServic ric.AspNetCore.dII aricAspNetCore.KestreI.dII MicrosoftServic ZicActors.dII MicrosoftServic MicrosoftServic ricServices.Remoting.dII Microsoft. Serviceric•z ricTransport.dII SystemZric.Ma na gement.ServiceModeI.dII Microsoft. Serviceri nternaI.Strings.dII Path bf3856ad364e... C: \SfD evCIuster\ ebAppTy ebApp2Pkg... C: \SfD evCIuster\ ebAppTy ebApp2Pkg.... bf38S6... C: \SfD evCIuster\ ebAppTy ebApp2Pkg.... C: \SfD ebAppTy ebApp2Pkg.... C: \SfD evCIuster\ ebAppTy ebApp2Pkg.... C: \SfD evCIuster\ ebAppTy ebApp2Pkg... C: \SfD evCIuster\ ebAppTy ebApp2Pkg.... C: \SfD evCIuster\ ebAppTy ebApp2Pkg... C: \SfD evCIuster\ ebAppTy ebApp2Pkg.... Optimized Yes Yes User Code N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A Symbol Status Symbols loaded. Symbols loaded. Cannot find or open the P... Symbols loaded. Cannot find or open the P... Symbols loaded. Symbols loaded. Symbols loaded. Symbols loaded. Symbols loaded. Symbols loaded. Cannot find or open the P... Symbol File D: m bo Is\Syste m D: m bo Is\Syste m D: m bo Is\Syste m O 13 14 111 112 115 116 117 Version 701 409.95... 303.150 604.658.95... 701 409.95... 604.658.95... 303.10 303.10 303.150 303.150 604.658.95... 604.658.95... 604.658.95... Timestamp 4/11/2D20 PM < Unknown> 4/25/2019 1225 PM 4/11/2020 PM 4/25/2019 1225 PM < Unknown> < Unknown> < Unknown> < Unknown> 4/25/2019 1226 PM 4/25/2019 1223 PM 4/25/2019 1224 PM

#5. Set a breakpoint in the Service Fabric SDK

Now you are ready to find the source file you are interested in and set a breakpoint. For example in \src\Microsoft.ServiceFabric.Services.Remoting\Client\ServiceRemotingExceptionHandler.cs in order to see how certain exceptions are handled on the client side.

Machine generated alternative text: if the exception is handled; bool IExceptionHand1er. TryHand1eException( Exceptionlnformation exceptionlnformation, OperationRetrySettings retrySettings, ExceptionHand1ingResu1t out otherwise, false.</returns> O 82 if (exceptionlnformation. Exception is FabricNotPrimaryException if (exceptionlnformation. TargetRep1ica = TargetRep1icaSe1ector. PrimaryRep1ica) esul ExceptionHand1ingRetryResu1t( new exceptionlnformation . Exception , false, retrySettings , retrySettings . DefaultmaxRetryCountForNonTransientErrors) ;

#6. Execute Code that will hit the breakpoint set in the Service Fabric SDK

When I navigate to http://localhost:8181/api/Actors/1 again, this code on the client side is hit in the Service Fabric SDK source code. Now I can inspect variables and step through the Service Fabric SDK source code.

Machine generated alternative text: MiceRemotingExceptionHandIer.cs -E Miscellaneous Files Startup.cs Service Manifest x ml Program.cs TestControIIer Web Host Environment.cs setup.cmd.backup Web Listener Program.cs Settings .x ml Startup.cs MicrosoftServiceFabricServices.Remoting.CIientServiceRemotingExceptionHandIer TyHandIeException(ExceptionInformation exceptionlnformation, OperationRetySettings retry' 824 <summary> Examines the exception and determines how that exception can be handled. < / summary> (param name="exceptionInformation">The information about the exception . (param name="retrySettings">The operation retry preferences (param name="resu1t">The result of the exception handling. <returns>true if the exception is handled; otherwise, false.</returns> bool IExceptionHand1er. TryHand1eException( Exceptionlnformation exceptionlnformation, OperationRetrySettings retrySettings, ExceptionHand1ingResu1t result) out a—if (exceptionlnformaticn. Exception is FebrickctPrimaryException if (exceptionlnformation. TargetRep1ica = TargetRep1icaSe1ector. PrimaryRep1ica) result — ExceptionHand1ingRetryResu1t( new exceptionlnformation. Exception , false, retrySettings , retrySettings . DefaultmaxRetryCountForNonTransientErrors) ; return true; ServiceTrace. Source. Writelnfo( 110% Watch I Search (Ctrl+E) Name No issues found TraceType , Search Depth: 3 Value {"My custom FabricTransientException"'r In: 82 Ch: 13 sec CRI X Call Stack Name exceptionlnformation.&ception Add item to watch Type System.Exception {Th... O MicrosoftServiceFabricServices.Remoting.dII!MicrosoftServiceFabricServices.Remoting.CIientServiceRemotingExceptionHandIer.Microso... C# Microsoft ServiceFabricServices.dII! Microsoft Microsoft ServiceFabricServices.dII! Microsoft ServiceFabricServices.Communication.CIient.CommunicationCIientFactory8ase< Microsoft S Microsoft ServiceFabricServices.dII! Microsoft MicrosoftServiceFabricServices.Remoting.dII!MicrosoftServiceFabricServices.Remoting.VI .FabricTransport.CIient.FabricTransportServiceRe... C# Microsoft ServiceFabricServices.dII! Microsoft ServiceFabric.Services.Communication.CIient.ServicePartitionCIient< Microsoft ServiceFabric.„.

0 comments

Discussion is closed.

Feedback usabilla icon