设置的格式必须为&QUOT的;名称=值&QUOT ;.不知道该怎么做 [英] Settings must be of the form "name=value". No idea what to do

查看:159
本文介绍了设置的格式必须为&QUOT的;名称=值&QUOT ;.不知道该怎么做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我解析一个Azure存储帐户的连接字符串,当我到达使用该连接字符串的应用程序的页面时,编译器捕捉到一个例外,说明设置必须的格式为名称=值

这是否意味着我应该纠正在我设置的appSettings app.config文件的东西吗?如果是这样你能马上发现什么毛病我的格式,将导致此例外?

 <?XML版本=1.0编码=UTF-8&GT?;
    <结构>
        <&的appSettings GT;
            <添加键=StorageConnectionStringVALUE =DefaultEndpointsProtocol = https和帐户名=我的帐户; AccountKey =的myKey/>
        <&的appSettings GT;
    < /结构>

这里的code创建云端储存对象的一个​​实例:

  CloudStorageAccount storageaccount = CloudStorageAccount.Parse(StorageConnectionString);        CloudTableClient tableClient = storageaccount.CreateCloudTableClient();        CloudTable austinBowlingAthletes = tableClient.GetTableReference(austinBowlingAthletesTable);


解决方案

您正在运行到这个错误的原因是因为你问 CloudStorageAccount.Parse 方法从字面上解析StorageConnectionString字符串,而不是存储在app.config文件此设置的值。你需要做的,而不是被读取从配置文件此设置的值。例如,在一个控制台应用程序,我会做这样的事情:

  VAR appSettingsReader =新AppSettingsReader();
         VAR的connectionString =(字符串)appSettingsReader.GetValue(StorageConnectionString,typeof运算(字符串));
         CloudStorageAccount storageaccount = CloudStorageAccount.Parse(的connectionString);

我不得不添加了 System.Configuration 程序集的引用这样做。

So I'm parsing a connection string for an Azure Storage Account and when I get to the page of the app that uses the connection string, the compiler catches an exception stating, "Settings must be of the form "name=value".

Does this mean that I should correct something in the app.config file where I set the appSettings? If so can you immediately spot something wrong with my format that would cause this exception?

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <appSettings>
            <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey" />
        <appSettings>
    </configuration>

Here's the code for creating an instance of CloudStorage object:

CloudStorageAccount storageaccount = CloudStorageAccount.Parse ("StorageConnectionString");

        CloudTableClient tableClient = storageaccount.CreateCloudTableClient ();

        CloudTable austinBowlingAthletes = tableClient.GetTableReference ("austinBowlingAthletesTable");

解决方案

The reason you're running into this error is because you're asking CloudStorageAccount.Parse method to literally parse "StorageConnectionString" string instead of the value of this setting stored in app.config file. What you need to do instead is read the value of this setting from the config file. For example, in a console application I would do something like this:

         var appSettingsReader = new AppSettingsReader();
         var connectionString = (string) appSettingsReader.GetValue("StorageConnectionString", typeof(string));
         CloudStorageAccount storageaccount = CloudStorageAccount.Parse(connectionString);

I had to add a reference for System.Configuration assembly to do so.

这篇关于设置的格式必须为&QUOT的;名称=值&QUOT ;.不知道该怎么做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆