question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException on Gateway mode on WebAssembly

See original GitHub issue

When doing a point operation over a non- existent container generates a NullReferenceException.

Steps to reproduce

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
{
    ConnectionMode = ConnectionMode.Gateway
};
CosmosClient cl = new CosmosClient("<connectionstring>", cosmosClientOptions);
await client.GetContainer("notExists", "notExists").CreateItem(new { id = "test" }, new PartitionKey("test"));

Yields this stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
  at Microsoft.Azure.Cosmos.GatewayStoreClient.CreateDocumentClientExceptionAsync (System.Net.Http.HttpResponseMessage responseMessage, Microsoft.Azure.Documents.IClientSideRequestStatistics requestStatistics) [0x00039] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\GatewayStoreClient.cs:177 
  at Microsoft.Azure.Cosmos.GatewayStoreClient.ParseResponseAsync (System.Net.Http.HttpResponseMessage responseMessage, Newtonsoft.Json.JsonSerializerSettings serializerSettings, Microsoft.Azure.Documents.DocumentServiceRequest request) [0x00241] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\GatewayStoreClient.cs:117 
  at Microsoft.Azure.Cosmos.GatewayStoreClient.InvokeAsync (Microsoft.Azure.Documents.DocumentServiceRequest request, Microsoft.Azure.Documents.ResourceType resourceType, System.Uri physicalAddress, System.Threading.CancellationToken cancellationToken) [0x000eb] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\GatewayStoreClient.cs:47 
  at Microsoft.Azure.Cosmos.GatewayStoreModel.ProcessMessageAsync (Microsoft.Azure.Documents.DocumentServiceRequest request, System.Threading.CancellationToken cancellationToken) [0x000ac] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\GatewayStoreModel.cs:61 
  at Microsoft.Azure.Cosmos.Routing.ClientCollectionCache.ReadCollectionAsync (System.String collectionLink, System.Threading.CancellationToken cancellationToken, Microsoft.Azure.Cosmos.IDocumentClientRetryPolicy retryPolicyInstance) [0x001da] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Routing\ClientCollectionCache.cs:86 
  at Microsoft.Azure.Documents.BackoffRetryUtility`1[T].ExecuteRetryAsync (System.Func`1[TResult] callbackMethod, System.Func`3[T1,T2,TResult] callShouldRetry, System.Func`1[TResult] inBackoffAlternateCallbackMethod, System.TimeSpan minBackoffForInBackoffCallback, System.Threading.CancellationToken cancellationToken, System.Action`1[T] preRetryCallback) <0x3d80510 + 0x000e6> in <filename unknown>:0 
  at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying (System.Runtime.ExceptionServices.ExceptionDispatchInfo capturedException) <0x3e03438 + 0x00022> in <filename unknown>:0 
  at Microsoft.Azure.Documents.BackoffRetryUtility`1[T].ExecuteRetryAsync (System.Func`1[TResult] callbackMethod, System.Func`3[T1,T2,TResult] callShouldRetry, System.Func`1[TResult] inBackoffAlternateCallbackMethod, System.TimeSpan minBackoffForInBackoffCallback, System.Threading.CancellationToken cancellationToken, System.Action`1[T] preRetryCallback) <0x3d80510 + 0x002c8> in <filename unknown>:0 
  at Microsoft.Azure.Cosmos.Common.CollectionCache+<>c__DisplayClass10_0.<ResolveByNameAsync>b__0 () [0x00064] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Routing\CollectionCache.cs:253 
  at Microsoft.Azure.Cosmos.Common.AsyncCache`2[TKey,TValue].GetAsync (TKey key, TValue obsoleteValue, System.Func`1[TResult] singleValueInitFunc, System.Threading.CancellationToken cancellationToken, System.Boolean forceRefresh) [0x002ec] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Routing\AsyncCache.cs:147 
  at Microsoft.Azure.Cosmos.Common.CollectionCache.ResolveByNameAsync (System.String apiVersion, System.String resourceAddress, System.Threading.CancellationToken cancellationToken) [0x000dc] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Routing\CollectionCache.cs:247 
  at Microsoft.Azure.Cosmos.ContainerCore.GetCachedContainerPropertiesAsync (System.Threading.CancellationToken cancellationToken) [0x000d3] in C:\GIT\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Resource\Container\ContainerCore.cs:313 

SDK 3.13.0 running on Blazor Web Assembly

Can’t repro on a normal NET Core application, but it seems the NRE comes from this line:

string resourceLink = responseMessage.RequestMessage.RequestUri.LocalPath;, responseMessage.RequestMessage seems to be null.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
j82wcommented, Sep 24, 2020

I agree that we should file it on their repo, but also do the fix the SDK to unblock users.

1reaction
FabianMeiswinkelcommented, Sep 24, 2020

Filing in their repo is fine - but this would take forever to get rolled out. So making the change proposed to safe-guard in our code is definitely a good choice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object reference not set to an instance of an object.
This code is blowing up on me, on the last line. No other errors thrown. This is some generated code from a Blazor...
Read more >
Blazor Server App component suddenly throwing null ...
Today a Blazor Server App I've been developing daily for a couple of weeks suddenly started throwing an exception in _Host.cshtml when I...
Read more >
What is a Null Reference Exception?
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable isn't referencing an ......
Read more >
NullReferenceException Class (System)
The exception that is thrown when there is an attempt to dereference a null object reference. public ref class NullReferenceException : Exception
Read more >
What is NullReferenceException in C#? - Code Maze
In C#, a NullReferenceException occurs when we try to access a variable whose value has not been set or has been set to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found