1
votes

I'm trying to connect to an Azure Cosmos DB. I just followed Microsoft's tutorial, but I doesn't work.

client = new DocumentClient(new Uri ("<MY ENDPOINT>"),"<MY KEY>");

This seems to work, but when I try to do anything inside the database, it keeps throwing Json Parser exception.

await this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = "DynamicForms" });

It throws the following error. I don't know If I am doing something wrong or is it really a bug.

at Newtonsoft.Json.JsonTextReader.ParseValue()\r\n
at Newtonsoft.Json.JsonTextReader.Read()\r\n
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)\r\n
at Microsoft.Azure.Documents.JsonSerializable.LoadFrom(JsonReader reader, JsonSerializerSettings serializerSettings)\r\n
at Microsoft.Azure.Documents.JsonSerializable.LoadFrom[T](JsonTextReader jsonReader, ITypeResolver1 typeResolver, JsonSerializerSettings settings)\r\n
at Microsoft.Azure.Documents.Client.ClientExtensions.CreateDocumentClientException(HttpResponseMessage responseMessage)\r\n
at Microsoft.Azure.Documents.Client.ClientExtensions.ParseResponseAsync(HttpResponseMessage responseMessage, JsonSerializerSettings serializerSettings)\r\n
at Microsoft.Azure.Documents.Client.GatewayServiceConfigurationReader.GetDatabaseAccountAsync(Uri serviceEndpoint)\r\n
at Microsoft.Azure.Documents.Routing.GlobalEndpointManager.GetDatabaseAccountFromAnyLocationsAsync(Uri defaultEndpoint, IList
1 locations, Func2 getDatabaseAccountFn)\r\n
at Microsoft.Azure.Documents.Client.GatewayServiceConfigurationReader.InitializeReaderAsync()\r\n
at Microsoft.Azure.Documents.Client.DocumentClient.InitializeGatewayConfigurationReader()\r\n
at Microsoft.Azure.Documents.Client.DocumentClient.GetInitializationTask()\r\n
at Microsoft.Azure.Documents.Client.DocumentClient.EnsureValidClientAsync()\r\n
at Microsoft.Azure.Documents.Client.DocumentClient.ReadDatabasePrivateAsync(String databaseLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance)\r\n
at Microsoft.Azure.Documents.BackoffRetryUtility
1.<>c__DisplayClass1_0.<b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteRetryAsync(Func1 callbackMethod, Func3 callShouldRetry, Func1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action1 preRetryCallback)\r\n
at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException)\r\n
at Microsoft.Azure.Documents.BackoffRetryUtility
1.ExecuteRetryAsync(Func1 callbackMethod, Func3 callShouldRetry, Func1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action1 preRetryCallback)\r\n
at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteAsync(Func1 callbackMethod, IRetryPolicy retryPolicy, CancellationToken cancellationToken, Action`1 preRetryCallback)\r\n
at Microsoft.Azure.Documents.Client.DocumentClient.CreateDatabaseIfNotExistsPrivateAsync(Database database, RequestOptions options)\r\n
at POCVueNetCoreMongo.Connector.GenerateStructureAsync() in D:\Projetos\DynaForms\POCVueNetCoreMongo\Data\Connector.cs:line 29

1
Just a comment, your code is spot on as far as I can tell. this is straight from the docs: using (IDocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key")) { Database db = client.CreateDatabaseIfNotExistsAsync(new Database { Id = "MyDatabase" }).Result; }Trey
@Trey it makes no difference if I use the using snippet or instantiate client object on class' constructorR.Silva
I'm not sure what the issue is, I'd contact their support.Trey

1 Answers

0
votes

It was a company proxy problem.