0
votes

I am having problems getting the Microsoft.Azure.Documents library to initialize the client in an azure worker role. I'm using Nuget Package 0.9.1-preview.

I have mimicked what was done in the example for azure document

When running locally through the emulator I can connect fine with the documentdb and it runs as expected. When running in the worker role, I am getting a series of NullReferenceException and then ArgumentNullException.

enter image description here

The bottom System.NullReferenceException that is highlighted above has this call stack enter image description here

so the nullReferenceExceptions start in this call at the new DocumentClient.

var endpoint = "myendpoint";
var authKey = "myauthkey";
var enpointUri = new Uri(endpoint);
DocumentClient client = new DocumentClient(endpointUri, authKey);

Nothing changes between running it locally vs on the worker role other then the environment (obviously).

Has anyone gotten DocumentDb to work on a worker role or does anyone have an idea why it would be throwing null reference exceptions? The parameters getting passed into the DocumentClient() are filled.

UPDATE: I tried to rewrite it being more generic which helped at least let the worker role run and let me attached a debugger. It is throwing the error on the new DocumentClient. Seems like some security passing is null. Both the required parameters on initialization are not null. Is there a security setting I need to change for my worker role to be able to connect to my documentdb? (still works locally fine)

UPDATE 2: I can get the instance to run in release mode, but not debug mode. So it must be something to do with some security setting or storage setting that is misconfigured I guess?

It seems I'm getting System.Security.SecurityExceptions - only when using The DocumentDb - queues do not give me that error. All Call Stacks for that error seem to be with System.Diagnostics.EventLog. The very first Exception I see in the Intellitrace Summary is System.Threading.WaitHandleCannotBeOpenedException.

More Info Intellitrace summary exception data: enter image description hereenter image description here

top is the earliest and bottom is the latest (so System.Security.SecurityException happens first then the NullReference)

2
where are you attempting to init the DocumentClient? In OnStart, RunAsync in the Loop? also, where are your configuration settings stored? if you deploy to Azure make sure the config settings are in the correct cscfg file (i.e. not in app.config)Ryan CrawCour

2 Answers

4
votes

The solution for me to get rid of the security exception and null reference exception was to disable intellitrace. Once I did that, I was able to deploy and attach debugger and see everything working.

Not sure what is between the null in intellitrace and the DocumentClient, but hopefully it's just in relation to the nuget and it will be fixed in the next iteration.

3
votes

unable to repro.

I created a new Worker Role. Single instance. Added authkey & endoint config to cscfg.

Created private static DocumentClient at WorkerRole class level

Init DocumentClient in OnStart Dispose DocumentClient in OnStop

In RunAsync inside loop, execute a query Works as expected.

Test in emulator works. Deployed as Release to Production slot. works. Deployed as Debug to Staging with Remote Debug. works. Attached VS to CloudService, breakpoint hit inside loop.

Working solution : http://ryancrawcour.blob.core.windows.net/samples/AzureCloudService1.zip