Value cannot be null. Parameter name: uriString

34,897

Solution 1

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

enter image description here

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.

enter image description here

Solution 2

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 *

Share:
34,897
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.