【问题标题】:Value cannot be null. Parameter name: uriString值不能为空。参数名称:uriString
【发布时间】:2019-07-06 00:05:28
【问题描述】:

我最近通过以下链接在 Visual Studio 2015 中创建了一个应用程序: https://azure.microsoft.com/en-in/documentation/articles/documentdb-dotnet-application/

但是当我构建解决方案时,它显示了以下错误:

值不能是null
参数名称:uriString
第 71 行:public static void Initialize()
第 72 行:{
第 73 行:client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["https://<db-name>.documents.azure.com:443/"]), ConfigurationManager.AppSettings["<db-key>"]);
第 74 行:CreateDatabaseIfNotExistsAsync().Wait();
第 75 行:CreateCollectionIfNotExistsAsync().Wait();

源文件:C:\Users\BHAVIN PATEL\Documents\Visual Studio 2015\Projects\documentdb-dotnet-todo-app-master\src\DocumentDBRepository.cs 行:73

我已从 Azure 中创建的 DocumentDB 应用程序将 URI 和主/次键插入到我的应用程序的 Web.config 文件中。

【问题讨论】:

  • 您的 App.config 中是否有 appSetting 键为“bhavin-patel.documents.azure.com:443”?
  • ANYTHING 之前 else:请立即更改您的数据库帐户访问密钥 - 您刚刚向全世界发布了它。我为你编辑了它,但人们仍然可以使用它。
  • 请不要删除问题并替换为解决方案。问题应该保持原样,一个问题,而答案部分可以用来建议其他人你做了什么来解决这个问题。或者,如果当前答案解决了问题,请考虑将其标记为已接受。
  • 正如 Bugs 所说:答案不属于问题。如果您想回答自己的问题,那么您可以这样做。但请不要理会这个问题。
  • 以防万一,它正在谈论的uriString来自这个ctor:docs.microsoft.com/en-us/dotnet/api/…

标签: asp.net azure-cosmosdb


【解决方案1】:

我在运行 Azure Function 时遇到此错误。

我正在读取来自Azure Key Vault 的连接字符串值之一,并且我已在我的 Azure Function 配置的应用程序设置中进行了设置。根据Microsoft Documentation,必须为Azure Function 设置Managed Identity,并使用创建的托管标识对象在Key Vault 配置中创建Access Policy,以便Azure Function 应用程序可以从密钥库。

我缺少此设置,因此键 ServiceBusConnectionString 的应用设置值始终为空,因此出现上述错误。配置访问策略后,错误消失了。希望对您有所帮助。

【讨论】:

    【解决方案2】:

    您的问题是数据库端点和密钥应该在 .config 文件中,像这样

    <appSettings>
      <add key="documentDbEndpoint" value="https://bhavin-patel.documents.azure.com:443/"/>
      <add key="documentDbKey" value="naw1rq0lhaPwzCSI1w69EQYEfUeL0rU*********************************"/>
    </appSettings>
    

    然后你应该使用配置管理器按键读取设置

    client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["documentDbEndpoint"]), ConfigurationManager.AppSettings["documentDbKey"]);
    

    请记住使用门户中的正确 documentDbKey。我已经用 * 掩盖了你的部分密钥

    【讨论】:

      猜你喜欢
      • 2013-09-13
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 2014-05-17
      相关资源
      最近更新 更多