service-fabric icon indicating copy to clipboard operation
service-fabric copied to clipboard

Could not load System.Fabric.AzureActiveDirectory.Client when using FabricClient to connect to an AAD-secured cluster

Open vturecek opened this issue 6 years ago • 4 comments

Connecting to a cluster secured with AAD using FabricClient in C# crashes with the following exception:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Fabric.AzureActiveDirectory.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
   at GetAccessToken(Char* authority, Char* audience, Char* client, Char* redirectUri, Boolean refreshSession, Char* outBuffer, Int32 outBufferSize)

Example code from a regular C# Console Application, assuming the destination cluster has AAD authentication enabled:

            string serverCertThumb = "A8136758F4AB8962AF2BF3F27921BE1DF67F4326";
            string connection = "clustername.westus.cloudapp.azure.com:19000";

            var claimsCredentials = new ClaimsCredentials();
            claimsCredentials.ServerThumbprints.Add(serverCertThumb);

            var fc = new FabricClient(claimsCredentials, connection);

            var ret = fc.ClusterManager.GetClusterManifestAsync().GetAwaiter().GetResult(); ;
                Console.WriteLine(ret.ToString());

If I add a reference to System.Fabric.AzureActiveDirectory.Client.dll to the Console App manually from the Service Fabric installation directory, then it works, but that assembly should be loaded automatically if it is a dependency. Note that the application compiles, but crashes at runtime.

Cluster version: 6.1.472 Microsoft.ServiceFabric package version: 6.1.472 Local runtime version installed: 6.1.472 Local OS: Windows 10

vturecek avatar Mar 28 '18 23:03 vturecek

How did you add System.Fabric.dll though?

belmaiastar avatar Mar 29 '18 00:03 belmaiastar

System.Fabric.dll comes with the Microsoft.ServiceFabric NuGet package.

vturecek avatar Mar 30 '18 18:03 vturecek

Experiencing this as well. Any updates? @athinanthny

Strandfelt avatar Mar 09 '21 10:03 Strandfelt

System.Fabric.dll comes with the Microsoft.ServiceFabric NuGet package.

This is completely unhelpful.

The DLL in question that is needed by the client but not distributed with it is System.Fabric.AzureActiveDirectory.Client.dll

On my machine I found it in C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code

You will also need https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/

Good luck making all of this work. I gave up.

darkoa-msft avatar Nov 15 '21 05:11 darkoa-msft