“ FormatException:在Azure Web App中使用重复的设置'DefaultEndpointsProtocol'找到了+存储连接字符串”

问题描述 投票:0回答:1

我有一个C#ASP.NET MVC应用程序(框架-非核心)。在Azure门户的Web App配置中,我针对各种应用程序要求设置了几个Azure存储连接字符串。

每当尝试读取连接字符串时,我都会遇到一个非常奇怪的错误。我得到:

[FormatException: Duplicate setting 'DefaultEndpointsProtocol' found.]
   Microsoft.WindowsAzure.Storage.CloudStorageAccount.<Parse>b__0(String err) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\Common\CloudStorageAccount.cs:525
   Microsoft.WindowsAzure.Storage.CloudStorageAccount.ParseStringIntoSettings(String connectionString, Action`1 error) in c:\Program Files     (x86)\Jenkins\workspace\release_dotnet_master\Lib\Common\CloudStorageAccount.cs:993
   Microsoft.WindowsAzure.Storage.CloudStorageAccount.ParseImpl(String connectionString, CloudStorageAccount& accountInformation, Action`1 error) in c:\Program Files     (x86)\Jenkins\workspace\release_dotnet_master\Lib\Common\CloudStorageAccount.cs:807
   Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(String connectionString) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\Common\CloudStorageAccount.cs:525

如您所见,它追溯到ParseStringIntoSettings内部的CloudStorageAccount.cs,它是Storage Nuget库的一部分。

这是该库中的代码(来自GitHub):

    private static IDictionary<string, string> ParseStringIntoSettings(string connectionString, Action<string> error)
    {
        IDictionary<string, string> settings = new Dictionary<string, string>();
        string[] splitted = connectionString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

        foreach (string nameValue in splitted)
        {
            string[] splittedNameValue = nameValue.Split(new char[] { '=' }, 2);

            if (splittedNameValue.Length != 2)
            {
                error("Settings must be of the form \"name=value\".");
                return null;
            }

            if (settings.ContainsKey(splittedNameValue[0]))
            {
                error(string.Format(CultureInfo.InvariantCulture, "Duplicate setting '{0}' found.", splittedNameValue[0]));
                return null;
            }

            settings.Add(splittedNameValue[0], splittedNameValue[1]);
        }

        return settings;
    }

我已经仔细检查了连接字符串,它们绝对都是100%正确的。直接从Azure门户本身复制。如果我对连接字符串进行硬编码,那么一切都将正常工作,只有当我从门户网站内的配置中拉出连接字符串时,问题才会浮出水面。

好像settings IDictionary参考,它显然是ParseStringIntoSettings中的局部变量是静态的而不是局部的,并且正在从另一个连接字符串中查找DefaultEndpointsProtocol名称/值。

代码调试并使用web.config存储设置在本地完美运行。这似乎仅发生在从门户网站获取设置时发生。

[此外,如果我将存储连接字符串放在应用程序设置以及门户网站的连接字符串中,也会发生错误。没有区别。

ASP.NET MVC 4.8框架。 Visual Studio2017。使用Azure DevOps构建并部署到Azure Web App。由于与Azure Functions的兼容性,我使用了Storage 8.7,尽管我已经在更高版本中进行了测试,但问题仍然存在。

c# asp.net-mvc azure azure-storage connection-string
1个回答
0
投票

一个非常奇怪的错误。在我这边尝试,一切都很好。

我建议您尝试remote debug apps。您也许可以检查从配置文件或门户网站配置获得的连接字符串。

© www.soinside.com 2019 - 2024. All rights reserved.