0

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

https://learn.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

Atul Takekar
  • 51
  • 13
  • @TheGeneral - I was using that code because it was provided in the official Microsoft azure page- https://learn.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 – Atul Takekar Oct 25 '21 at 21:21

1 Answers1

1

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.

enter image description here

OUTPUT

enter image description here

ShrutiJoshi-MT
  • 1,622
  • 1
  • 4
  • 9
  • StorageCredentials creds = new StorageCredentials(("name"),("key")); I tried the to pass but that didnt work either, it showing same error at same stage – Atul Takekar Oct 26 '21 at 13:49
  • I have this warning message while I run the project `warning NU1701: Package 'Microsoft.Azure.ConfigurationManager 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.` – Atul Takekar Oct 26 '21 at 13:52
  • which version of .net framework you are using? – ShrutiJoshi-MT Oct 26 '21 at 14:49
  • using .NET 5.0 for this example – Atul Takekar Oct 26 '21 at 17:54
  • 1
    Check the with `Microsoft.Azure.ConfigurationManager `, In application where you using this package ,I think you used it to read the Credentials from `app.config`.Please remove that package and try it again and let me know still facing issue. – ShrutiJoshi-MT Oct 27 '21 at 12:18
  • Started working thank you – Atul Takekar Oct 27 '21 at 19:50