Graham Robinson Graham Robinson - 6 months ago 30
Vb.net Question

Cannot get Azure DocumentDB to work with VB.NET

I'm having difficultly using DocumentDB to create documents using visual studio 2015 update 2 and Vb.net

The call to CreateDocumentAsync goes away and never comes back. I've attempted the same calls in C# using the same parameters and they work fine, but my customer requires that i use Vb.NET

I've reduced the problem down to a test program which is shown below.

Main.vb

Imports Microsoft.Azure.Documents
Imports Microsoft.Azure.Documents.Client

Module Module1


Sub Main()
Test()
End Sub

Public Async Sub Test()

Dim client As New DocumentClient(New Uri("https://XXXXXXX.documents.azure.com:443/"), "XXXXXXXXX==")


' Create a new document


Dim x As New JGR
x.id = Guid.NewGuid.ToString()
x.name = "Graham"
Dim y As ResourceResponse(Of Document) = Await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("XXXX-Playground", "XXXXXX"), x, Nothing, True)
End Sub
End Module


JGR.VB

Imports Newtonsoft.Json

Public Class JGR

<JsonProperty(PropertyName:="id")>
Property id As String
Property name As String
End Class

Answer

Your code seems to run just fine. I've created a new single partition collection and tested with Microsoft.Azure.DocumentDB nuget package 1.7.1 with Newtonsoft.Json version 6.0.8. I've also tried updating to Newtonsoft.json 8.0.3, still runs fine. The request charge for creating the document is 5.52

I would recommend you to change the method signature from Sub to Function which returns task, in order to capture errors - if not the program may exit before your request is completed.

Sub Main()
    Test().Wait()
End Sub

Public Async Function Test() As Task
    Dim client As New DocumentClient(New Uri("https://stacktest.documents.azure.com:443/"), "g6YlmeYQkoIlrKhuToNIF7kDeHn5VSKiljx4FOijNUtae25cEyNwnKO5TXCT7Y2yWifldxwKb8AIZWhaAtQ5tw==")


    ' Create a new document

    Dim x As New JGR
    x.id = Guid.NewGuid.ToString()
    x.name = "Graham"
    Dim y As ResourceResponse(Of Document) = Await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("db1", "col1"), x, Nothing, True)
End Function