TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
481.9k
The name does not exist in the current context
Aug 26 2019 9:25 AM
Hi team
Can anyone help with this logic error, "the name kvClient does not exist in the current context". Here is my code below.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Configuration;
using
System.IO;
using
System.Threading.Tasks;
using
Microsoft.IdentityModel.Clients.ActiveDirectory;
using
Microsoft.Azure;
using
Microsoft.Azure.KeyVault;
using
Microsoft.Azure.Storage;
using
Microsoft.Azure.Storage.Auth;
using
Microsoft.Azure.Storage.Blob.Protocol;
using
Microsoft.Azure.Storage.Blob;
using
System.Threading;
using
Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using
Microsoft.Azure.Management.ResourceManager.Fluent;
namespace
EncryptionApplication
{
class
Program
{
static
void
Main(
string
[] args)
{
Program p =
new
Program();
string
secretName =
"MySecret10"
;
string
kvURL =
"https://entsavmvault.vault.azure.net/"
;
//
string
clientId = Environment.GetEnvironmentVariable(
"akvClientId"
);
string
clientSecret = Environment.GetEnvironmentVariable(
"akvClientSecret"
);
string
tenantId = Environment.GetEnvironmentVariable(
"akvTenantId"
);
string
subscription = Environment.GetEnvironmentVariable(
"akvSubscription"
);
AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud).WithDefaultSubscription(subscription);
KeyVaultClient keyVaultClient =
new
KeyVaultClient(async (authority, resource, scope) => {
var adCredential =
new
ClientCredential(clientId, clientSecret);
var authenticationContext =
new
AuthenticationContext(authority,
null
);
return
(await authenticationContext.AcquireTokenAsync(resource,adCredential)).AccessToken;
Console.WriteLine(
"Input the value of your secret"
);
string
secretValue = Console.ReadLine();
Console.WriteLine(
"Your secret is '"
+ secretValue +
"'."
);
Console.WriteLine(
"Saving the value of your secret to your key vault"
);
var result = p.SetSecret(kvClient, kvURL, secretName, secretValue);
System.Threading.Thread.Sleep(5000);
Console.WriteLine(
"done"
);
Console.WriteLine(
"Forgetting your secret"
);
secretValue =
""
;
Console.WriteLine(
"Your secret is ''"
+ secretValue);
Console.WriteLine(
"Retrieving your secret from key vault"
);
var fetchedSecret = p.GetSecret(kvClient,kvURL,secretName,secretValue);
secretValue = fetchedSecret.Result;
Console.WriteLine(
"Your secret is"
+ secretValue);
});
}
public
async Task GetSecret(KeyVaultClient kvClient,
string
kvURL,
string
secretName)
{
var keyvaultSecret = await kvClient.GetSecretAsync($
"{kvURL}/secrets/{secretName}"
).ConfigureAwait(
false
);
return
keyvaultSecret.Value;
}
public
async Task SetSecret(KeyVaultClient kvClient,
string
kvURL,
string
secretName,
string
secretValue)
{
await kvClient.SetSecretAsync($
"{kvURL}"
, secretName, secretValue);
return
true
;
}
}
}
What am i missing?
Reply
Answers (
2
)
Retrieving records from database
Error for Load 'Microsoft.VisualBasic.VBMath in .net core