简体   繁体   中英

Error while getting the config file parameters in C# console application

I am following this page to encrypt the blob using azure key vault using C#

https://docs.microsoft.com/en-us/azure/storage/blobs/storage-encrypt-decrypt-blobs-key-vault?WT.mc_id=Portal-Microsoft_Azure_Support&tabs=dotnet11#use-key-vault-secrets

But getting an error in this code block

StorageCredentials creds = new StorageCredentials(
                CloudConfigurationManager.GetSetting("accountName"),
                CloudConfigurationManager.GetSetting("accountKey")
            );

Unhandled exception. System.Runtime.InteropServices.MarshalDirectiveException : Cannot marshal 'parameter #1': Invalid managed/unmanaged type combination (Marshaling to and from COM interface pointers isn't supported).

app.config

<appSettings>
    <add key="accountName" value="myaccount"/>
    <add key="accountKey" value="theaccountkey"/>
    <add key="clientId" value="theclientid"/>
    <add key="clientSecret" value="theclientsecret"/>
    <add key="container" value="stuff"/>
</appSettings>

I tried the solutions given in link below, but those didn't work either

System.argumentnullexception is null using microsoft azure storage

I tried to reproduce the scenario in my system .Not facing the error that you are getting .I passed the credentials directly instead of reading them from app.config .I think issue with reading credentials from app.config Pass the credentials directly .

在此处输入图片说明

OUTPUT

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM