0
votes

I Have deployed a secure service fabric cluster and able to connect through browser and powershell using certificates. When trying the same from C# getting error as:

An error occurred during this execution

at System.Fabric.Interop.Utility.WrapNativeSyncInvoke[TResult](Func`1 func, String functionTag, String functionArgs) at System.Fabric.Interop.Utility.RunInMTA(Action action) at System.Fabric.FabricClient.InitializeFabricClient(SecurityCredentials credentialArg, FabricClientSettings newSettings, String[] hostEndpointsArg) at CloseAppAPI.Controllers.CloseClientController.d__0.MoveNext() in C:\Users\kumar.kshitij\source\repos\CloseAPP\CloseAppAPI\Controllers\CloseClientController.cs:line 39".

Attaching Image and code for the reference. Please anyone let me know if you have a solution.

screenshot

C# Code Below:-

        string CommonName = "www.cluster1.eastus2.cloudapp.azure.com";
        string connection = "cluster1.eastus2.cloudapp.azure.com:19000";

        var xc = GetCredentials(CommonName);

            var fc = new FabricClient(xc, connection);

             static X509Credentials GetCredentials(string clientCertThumb, 
              string serverCertThumb, string name)
          {
        X509Credentials xc = new X509Credentials();
        xc.StoreLocation = StoreLocation.LocalMachine;
        xc.StoreName = "Personal";
        xc.FindType = X509FindType.FindByThumbprint;
        xc.FindValue = "08DF81BD17507D4ADEC4DEE075E33A3CB8C8D04E";

        xc.RemoteCommonNames.Add(name);        

   xc.RemoteCertThumbprints.Add("3D317C232F06AC1F5A2C8D16CC2830D6F7CD5FAC");
        //xc.ProtectionLevel = ProtectionLevel.EncryptAndSign;
        return xc;
    }
1

1 Answers

0
votes

You're using different values for StoreLocation and StoreName in PowerShell.

Try replacing

xc.StoreName = "Personal"; xc.StoreLocation = StoreLocation.LocalMachine;

with

xc.StoreLocation = StoreLocation.CurrentUser; xc.StoreName = "TrustedPeople";