简体   繁体   中英

Azure Document Db Worker Role

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.

在此处输入图片说明

The bottom System.NullReferenceException that is highlighted above has this call stack 在此处输入图片说明

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: 在此处输入图片说明在此处输入图片说明

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM