//Get ApplicationId of Service Principal if user doesn't provide this parameter
        private Guid GetApplicationId(Guid applicationId)
        {
            if (applicationId != Guid.Empty)
            {
                return(applicationId);
            }

            GraphRbacManagementClient graphClient = AzureSession.Instance.ClientFactory.CreateArmClient <GraphRbacManagementClient>(
                DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.Graph);

            graphClient.TenantID = DefaultProfile.DefaultContext.Tenant.Id.ToString();

            Microsoft.Azure.Graph.RBAC.Version1_6.Models.ServicePrincipal sp = null;
            try
            {
                sp = graphClient.ServicePrincipals.Get(ObjectId.ToString());
            }
            catch (Microsoft.Azure.Graph.RBAC.Version1_6.Models.GraphErrorException e)
            {
                string errorMessage = e.Message + ". Please specify Application Id explicitly by providing ApplicationId parameter and retry.";
                throw new Microsoft.Azure.Graph.RBAC.Version1_6.Models.GraphErrorException(errorMessage);
            }

            var spApplicationId = Guid.Empty;

            Guid.TryParse(sp.AppId, out spApplicationId);
            Debug.Assert(spApplicationId != Guid.Empty);
            return(spApplicationId);
        }
        //Get ApplicationId for the given ObjectId.
        private Guid GetApplicationId()
        {
            GraphRbacManagementClient graphClient = AzureSession.Instance.ClientFactory.CreateArmClient <GraphRbacManagementClient>(
                DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.Graph);

            graphClient.TenantID = DefaultProfile.DefaultContext.Tenant.Id.ToString();

            Microsoft.Azure.Graph.RBAC.Version1_6.Models.ServicePrincipal sp = graphClient.ServicePrincipals.Get(ObjectId.ToString());

            var applicationId = Guid.Empty;

            Guid.TryParse(sp.AppId, out applicationId);
            Debug.Assert(applicationId != Guid.Empty);
            return(applicationId);
        }