'Connecting to Dynamics Dataverse from Azure Web App - getting "object not set to an instance of an object"

We have an API, written in C# .NET Framework that connects to the OrganizationService and the OrganizationServiceContext of our Dynamics instance.

We are getting an "object not set to an instance of an object".

We have isolated the exact line the error is occurring on.

  • When we create a connection to the OrganizationService the connection succeeds (in that the object is not null).
  • When we then create a context from the new service object this is also succeeding (in that the object is not null)
  • When we fire a linq query using the context we get the error.

E.g. the line may be:

var return = (from c in Context.CreateQuery("transactioncurrency") select c).ToList() 

and it is this line that is causing the "object not set to an instance of an object".

Note that in the example line above the variable "Context" is NOT null, so that is not the problem. Further note that this code works perfectly when run from a local PC. It is ONLY when the code is deployed to the Azure Web App that it fails to 'talk' to Dynamics.

It seems that this is not an uncommon thing to want to do. Can anyone help me with what I am doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source