【问题标题】:StorageConnectionString does not work when it is located in App.configStorageConnectionString 位于 App.config 中时不起作用
【发布时间】: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["StorageConnectionStr‌​ing"]);

但抛出以下错误

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


【解决方案1】:

您的项目中应该有对 System.Configuration 的引用和相同的命名空间声明。默认情况下,某些项目模板(如控制台应用程序)不引用此程序集,因此您必须手动引用它。 此外,请检查您的项目是否使用最新的 Azure SDK。右键单击您的 Azure 项目并选择属性。在“应用程序”选项卡下,您应该会看到一个用于更新您的 Azure SDK 的按钮。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2010-09-23
    相关资源
    最近更新 更多