【发布时间】:2016-02-16 15:14:44
【问题描述】:
我有 .NET 控制台应用程序项目,我正在尝试连接到 Azure 存储。
我将此代码粘贴到 App.config 文件中
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=<accountName>;AccountKey=<accessKey>" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
在 program.cs 中我正在使用此代码
// Retrieve storage account from app setting (App.config)
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
但抛出以下错误
An unhandled exception of type 'System.ArgumentNullException' occurred in Microsoft.WindowsAzure.Storage.dll
当我直接粘贴 StorageConnectionString 时它可以工作!
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=h.....")
有什么问题?
【问题讨论】:
-
您需要将配置粘贴到
App.config而不是App.setting。 -
谢谢,但这是我的错字,我已经在 App.config 中找到了。我编辑了问题。
标签: .net console-application azure-storage