简体   繁体   中英

Value cannot be null. Parameter name: uriString

I recently created an application in Visual Studio 2015 following the link: https://azure.microsoft.com/en-in/documentation/articles/documentdb-dotnet-application/

But when I build the solution, it showed me the following error:

Value cannot be null .
Parameter name: uriString
Line 71: public static void Initialize()
Line 72: {
Line 73: client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["https://<db-name>.documents.azure.com:443/"]), ConfigurationManager.AppSettings["<db-key>"]);
Line 74: CreateDatabaseIfNotExistsAsync().Wait();
Line 75: CreateCollectionIfNotExistsAsync().Wait();

Source File: C:\\Users\\BHAVIN PATEL\\Documents\\Visual Studio 2015\\Projects\\documentdb-dotnet-todo-app-master\\src\\DocumentDBRepository.cs Line: 73

I have inserted the URI and Primary/Secondary Key in Web.config file of my application from the DocumentDB application created in Azure.

Your problem is that the database endpoint and key should be in the .config file, like this

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

And you should then use the configuration manager to read the setting by the key

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

Remember to use the correct documentDbKey from the portal. I have masked part of your key with *

I was getting this error when I was running my Azure Function .

在此处输入图片说明

I was reading one of the connection string value from Azure Key Vault and I had set this in the app settings of my Azure Function configuration. As per the Microsoft Documentation , it is mandatory to set the Managed Identity for the Azure Function and created an Access Policy in the Key Vault configuration by using the managed identity object created, so that Azure Function application can read the values from the Key Vault.

I was missing this settings, so that the app setting value of the key ServiceBusConnectionString was always null, thus the mentioned error. After configuring the access policy, the error was gone. Hope it helps.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM