microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
284 stars 52 forks source link

Possible null reference issue 1.1.32 #466

Open krselvaer opened 2 months ago

krselvaer commented 2 months ago

Hi,

We recently tried to upgrade our Dataverse package quite a few "notches" from 1.0.26 to the latest release 1.1.32. After this upgrade we saw an irregular amount of NullReferenceExceptions. We were unable to figure out a consistency for when this error occurred in terms of reproducing it etc. We eventually downgraded again and our problems disappeared. We haven't looked too much into this issue. But I figured I'd report it in case it is an issue with the newest release that is not specific to us.

Let me know if you need more details :)

Part of the Stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.Linq.QueryProvider.RetrieveEntityCollection(OrganizationRequest request, NavigationSource source)
   at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute(QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List1 linkLookups, String& pagingCookie, Boolean& moreRecords)
   at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List1 linkLookups)
   at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression)
   at Microsoft.Xrm.Sdk.Linq.QueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
MattB-msft commented 1 month ago

Given the error your seeing it looks like this is coming up out of the Linq provider included in the most recent release. can you provide a sample / repro we can use to debug this?

krselvaer commented 1 month ago

Hi again :)

I have tried to do some more digging and these seem to be the steps we do to create this error, I have only been able to recreate it for system users and it isn't every run where the error happens. The process we do is:

  1. Create a SingleOrDefault for the SystemUserSet
  2. Our Queryable looks like crmContext.SystemUserSet.SingleOrDefault(x => x.Id == Guid.Parse(key))
  3. Creates a query for SystemUser
  4. As far as I can tell this looks fine in ServiceClient up until Command_Execute(...)
  5. Here it looks like DataverseService is null (sometimes the request was also suddenly null here). But this is obviously deconstructed from the Nuget package etc. So I'm not confident in the details at this point. Especially as I could see that this service wasn't null just before?

I will note that it looks like we do two identical async calls about the same time for two different system users (or sometimes the same). The way this is handled from our side looks a bit weird.

Some more details: Example

The criteria for this screenshot is Equals systemuserid with a Guid.

This is how we instantiate the ServiceClient: new ServiceClient(connectionString, clientId, clientSecret, false);

MattB-msft commented 1 month ago

Thanks.. this helps... we will see if we can run it down.

krselvaer commented 3 weeks ago

Hi,

I was wondering if there was any update on this issue? Or if there is an estimate for when this will be looked at? :)