Closed Gareth064 closed 10 months ago
I just attached the bugger again and when it hits the exception, inside the ServiceClient class, the "Details" are only showing this
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.PowerPlatform.Dataverse.Client
StackTrace:
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.Command_Execute(OrganizationRequest req, String errorStringCheck, Boolean bypassPluginExecution) in Microsoft.PowerPlatform.Dataverse.Client\ServiceClient.cs:line 1299
@MattB-msft sorry to tag you directly, but you appear to answer a lot of the issues and discussions on here. My management are asking me to rollback the upgrade if I can't figure this out in the next 24 hours :(
Would you be able to provide feedback on this issue?
Anyone able to help with this?
We are taking a look at this now.. sorry for the delay... the team has been very busy with a number of projects.
Thank you @MattB-msft. I had to beef up my resilience layer in my code to implement better retries. The request works a second time.
This appears to be very intermittent. But enough that we come into work each day with hundreds of errors logged related to this.
Thanks for this... we have been having a heck of a time trying to run this down.
I wonder if this is a 'hardware' clock issue.. StopWatch is a low level handler.. see : https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch?view=net-8.0#remarks
Im going to have the team put in a speculative fix here to see if that resolves it.
We have included the speculative fix in 1.1.17 and are going to close this issue...if it resurfaces, please reopen.
Hi @MattB-msft , I finally got around to trying 1.1.17
Unfortunately it hasn't worked out well.
Here what I've done.
Whilst still on v1.1.14, I sent 1000 sequential requests to the function app (that hosts the code using the SDK) and it handled all 1000 fine.
I upgrade the SDK to 1.1.17 and sent 1000 sequential requests again.
After 252 successful requests, the function app appears to have died/shutdown as I started to get a response saying "Function host is not running."
The next 171 requests continued to get the same "Function host is not running." response.
After the function app appeared to come back online again, the final 577 requests failed with the following error returned from the SDK
Unable to connect to Dataverse: Unable to cast object of type 'generatedProxy_2' to type 'Microsoft.PowerPlatform.Dataverse.Client.IOrganizationServiceAsync'.
Source: System.Private.CoreLib
Method: ChkCastAny
DateUTC: 4/10/2024
TimeUTC: 3:44:18 PM
Error: Unable to cast object of type 'generatedProxy_2' to type 'Microsoft.PowerPlatform.Dataverse.Client.IOrganizationServiceAsync'.
HelpLink Url: Not Provided
Stack Trace: at System.Reflection.DispatchProxy.Create[T,TProxy]()
at System.ServiceModel.Channels.ServiceChannelProxy.CreateProxy[TChannel](MessageDirection direction, ServiceChannel serviceChannel)
at System.ServiceModel.Channels.ServiceChannelFactory.CreateProxy[TChannel](MessageDirection direction, ServiceChannel serviceChannel)
at System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel[TChannel](EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannelInternal()
at System.ServiceModel.ClientBase`1.get_Channel()
at System.ServiceModel.ClientBase`1.get_InnerChannel()
at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.ConnectAndInitServiceAsync(OrganizationDetail orgdata, Boolean IsOnPrem, Uri homeRealmUri)
at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.DoDirectLoginAsync(Boolean IsOnPrem)
at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.InitServiceAsync()
======================================================================================================================
A few questions
Regarding my previous message, to get passed it, I changed from a Scoped service to a Singleton service in my startup class and it has allowed high volume requests to go through without issue.
Back to the original issue, I can confirm that this error is no longer happening. It has been live in production for 3 days now and no occurrence has happened, where previously there were hundreds of exceptions daily.
Host: Azure Function App (Consumption) - HTTP Trigger Dotnet version: 6.00 SDK Version: 1.1.14
I upgraded my SDK from 0.6.1 to 1.1.14 last night.
Since doing so, I am getting exceptions being thrown which didn't happen on 0.6.1. (I know its a big jump in version)
This is a function app which runs at a pretty high volume to sync records between Dataverse and a SQL database. Daily volumes are roughly 90k requests per day, with the higher portion of those happening between 8am and 6pm.
I can't replicate it in a non-prod environment at the moment so I attached a debugger to the production instance running in Azure.
Here is a screenshot of where it throws the exception each time
This is how I am registering the ServiceClient in DI
Then its used like so
It is throwing these errors when I use the
RetrieveMultipleAsync
method it seems.Trace Logs from app insights make me believe the connection is created fine because before we start making any calls, we log which Organization we are connected to. And that trace log is present every time.
To be clear, this is intermittent. in the past 20 hours (since it was updated) this function app has handled 78k requests, with 381 of these failing with the above error.
I am putting my money on something to do with how I am creating the ServiceClient on a per request basis?
I did notice that the SDK method it throws from is called
Execute_Command
which doesn't appear to be async. Where there is a version of it which is asyncExecute_CommandAsync
Has anyone got any ideas?