1

Currently I am trying with below code but getting System.NullReferenceException: 'Object reference not set to an instance of an object.'.

using Microsoft.Azure.Management.RecoveryServices.Backup;
public static ISecurityPINsOperations SecurityPINs { get; }
public static class GenerateSecurityPIN
    {
        private static readonly ISecurityPINsOperations Operations1;
        var pin = await SecurityPINs.GetAsync("rsv-itops-azure-support", "rg-azure-itops-rnd-dev");
    }

Referencing below links : https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.recoveryservices.backup.securitypinsoperationsextensions?view=azure-dotnet

DnyaneshSurya
  • 187
  • 1
  • 1
  • 14

1 Answers1

1

You should install Microsoft.Azure.Management.RecoveryServices.Backup -Version 4.1.5-preview with below command.

Install-Package Microsoft.Azure.Management.RecoveryServices.Backup -Version 4.1.5-preview

Then you sample code, should be like this, you need create RecoveryServicesBackupClient first.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Management.RecoveryServices.Backup;
using Microsoft.Azure.Management.ResourceManager.Fluent;

namespace ConsoleApp2
{
    static class Program
    {
        static void Main(string[] args)
        {
            var subscriptionId = "";
            var vaultname = "";
            var resourcegroup = "";
            var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"Auth file path");
            var client = new RecoveryServicesBackupClient(credentials) { SubscriptionId = subscriptionId };
            var pin = client.SecurityPINs.GetAsync(vaultname,resourcegroup).Result.SecurityPIN;
        }
    }
}

If you don't wante to upgrade package, you also can use restapi to get PIN.

Related post:

fetch Azure 'Files and folders' Job status using Powershell or C#

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Thank you very much for reply . I trying with below code: var credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(clientCredentials.ClientId, clientCredentials.ClientSecret, requestObject.TenantId, AzureEnvironment.AzureGlobalCloud); var client = new RecoveryServicesBackupClient(credentials) { SubscriptionId = requestObject.SubscriptionId }; var pin = client.SecurityPINs.GetAsync(requestObject.VaultName, requestObject.ResourceGroupName); But getting "WaitingForActivation" Please help me on this. – DnyaneshSurya Mar 04 '21 at 08:09
  • @DnyaneshSurya If my solution inspires or helps you, could you mark my answer as [accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) , Tks~ – Jason Pan Mar 04 '21 at 08:09
  • @DnyaneshSurya var pin = client.SecurityPINs.GetAsync(vaultname, resourcegroup).Result.SecurityPIN; – Jason Pan Mar 04 '21 at 09:40