Attempting to connect to azure database has suddenly stopped working, throwing exceptions

大憨熊 提交于 2019-12-23 02:04:21

问题


I have the following code running in an Azure Function (V2);

 new DocumentClient(new Uri(keys.dbEndPoint), keys.dbPrimaryKey);

Which has worked fine running in azure functions on localhost until today, without changing anything I'm now getting the following exception:

Data [IDictionary]:{System.Collections.ListDictionaryInternal} HResult [int]:-2146233036 HelpLink [string]:null InnerException [Exception]:{System.NullReferenceException: Object reference not set to an instance of an object.} Message [string]:"The type initializer for 'Microsoft.Azure.Documents.UserAgentContainer' threw an exception." Source [string]:"Microsoft.Azure.DocumentDB.Core" StackTrace [string]:" at Microsoft.Azure.Documents.UserAgentContainer..ctor()\r\n at Microsoft.Azure.Documents.Client.ConnectionPolicy..ctor()\r\n at Microsoft.Azure.Documents.Client.ConnectionPolicy.get_Default()\r\n
at Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel)\r\n at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel)\r\n at Platform.AzureConfig.get_Database() in D:\DeansCloud\AzureConfig.cs:line 60" TargetSite [MethodBase]:{Void .ctor()} TypeName [string]:"Microsoft.Azure.Documents.UserAgentContainer" Static members Non-Public members

Which doesn't say much, the inner exception mentions a null reference exception:

Message [string]:"Object reference not set to an instance of an object."

Is this an issue with azure cosmos db now? Do I need to update something?


回答1:


I found the issue to be the latest azure core tools, downgrading to version 24 fixed it.




回答2:


Instead of creating your own DocumentClient, try to use the binding-based version. This will also give you better performance. See an example here or here.



来源:https://stackoverflow.com/questions/50562026/attempting-to-connect-to-azure-database-has-suddenly-stopped-working-throwing-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!