Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Exceptions in Retrieve and RetrieveMultiple thrown by internal CRM mechanisms

(0) ShareShare
ReportReport
Posted on by 210

I'm getting a strange NullReference when executing RetrieveMultiple in MS CRM 365 (online).

Unfortunately, the exception doesn't happen always, so it's hard to reproduce. The logs I was able to get show the following:

System.NullReferenceException: Object reference not set to an instance of an object.

Server stack trace: 
at Microsoft.Crm.Sandbox.SandboxCallbackService.ProcessException(Exception e, SandboxSdkClient client)
at Microsoft.Crm.Sandbox.SandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object sandboxTraceSettingsObj)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Crm.Sandbox.ISandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object traceSettings)
at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(OrganizationRequest request)
at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.RetrieveMultipleInternal(QueryBase query)
at CRM.Plugins.Messages_Entry_Points.Report12EntryPlugin.ValidateReportInput(LocalPluginContext obj)
at CRM.Plugins.Base_Files.Plugin.Execute(IServiceProvider serviceProvider)

The stack trace suggests the exception is thrown inside Microsoft CRM code (Microsoft.Crm.Sandbox.SandboxOrganizationService), not something a typical CRM developer has access to.

Here's the relevant code fragment (the ValidateReportInput method):

var groupSelector = preImage.GetAttributeValue<string>("str_customergroupcode");
var activityId = preImage.GetAttributeValue<string>("str_activityid");
if (!String.IsNullOrEmpty(groupSelector))
{
var existingEntriesQuery = new QueryByAttribute("str_report12element") { ColumnSet = new ColumnSet("str_leadid", "str_contactid") };
existingEntriesQuery.AddAttributeValue("str_customergroupcode", groupSelector);
existingEntriesQuery.AddAttributeValue("str_activityid", activityId);
var results = obj.OrganizationService.RetrieveMultiple(existingEntriesQuery).Entities.Select(r => r.ToEntity<str_report12element>());
//some validation checks here; error seems to occurs in RetrieveMultiple above
}

str_report12element is a model of a custom entity created mostly for technical reasons (i.e. it's not viewed by the users directly). The fields referenced in the query are regular string fields ("single line of text").

I know QueryByAttribute permits the use of null as query values (I've checked), so the query should work fine even if the two parameters (groupSelector and activityId in this case) are null. The OrganizationService object is clearly defined, as the exception seems to happen somewhere inside the RetrieveMultiple method. I also don't think Entities is null as the stack trace is, again, pointing towards the RetrieveMultiple method.

I've also considered if some other plugin isn't being triggered by this CRM message that could throw such an error, but the entity, being a custom one, is very basic. Additionally there are no plugins registered on the Retrieve or RetrieveMultiple messages for this entity.

A very similar error has been popping up in a different section, this time related to the Retrieve method.

    System.NullReferenceException: Object reference not set to an instance of an object.
    
    Server stack trace: 
       at Microsoft.Crm.Sandbox.SandboxCallbackService.ProcessException(Exception e, SandboxSdkClient client)
       at Microsoft.Crm.Sandbox.SandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object sandboxTraceSettingsObj)
       at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
    
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Microsoft.Crm.Sandbox.ISandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object traceSettings)
       at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(OrganizationRequest request)
       at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.RetrieveInternal(String entityName, Guid id, ColumnSet columnSet)
       at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.Retrieve(String entityName, Guid entityId, ColumnSet columnSet)
       at CRM.Plugins.Messages_Entry_Points.ContactEntityDMSSyncPlugin.CreateContactTransportModel(LocalPluginContext localContext, Contact contact)
       at CRM.Plugins.Messages_Entry_Points.ContactEntityDMSSyncPlugin.CreateSBusSync(LocalPluginContext obj)
       at CRM.Plugins.Base_Files.Plugin.Execute(IServiceProvider serviceProvider)

There are 3 calls to `Retrieve` in the `CreateContactTransportModel` method, all of which are fairly simple:

    if (contact.str_address1_countyid != null)
    {
        var county = localContext.OrganizationService.Retrieve("str_county", contact.str_address1_countyid.Id, new ColumnSet("str_name")).ToEntity<str_county>();
        result.County = county.str_name;
    }
    
    if (contact.str_City != null)
    {
        var city = localContext.OrganizationService.Retrieve("str_city", contact.str_City.Id, new ColumnSet("str_name")).ToEntity<str_city>();
        result.City = city.str_name;
    }
    
    if (contact.str_titleid != null)
    {
        var title = localContext.OrganizationService.Retrieve("str_title", contact.str_titleid.Id, new ColumnSet("str_name")).ToEntity<str_title>();
        result.Title = title.str_name;
    }

The only conclusion I can come up with is that something wrong is happening inside MS CRMs internal code and that's a very scary thought.

I'd like to know how I can work around this, or if this is something that I should get MS support to have a look at. Or perhaps, given that MS CRM does have a few "secrets" here or there, this is one of them and someone could shed some light on what's going on?

*This post is locked for comments

  • Cosair Profile Picture
    Cosair 215 on at
    RE: Exceptions in Retrieve and RetrieveMultiple thrown by internal CRM mechanisms

    I am observing the same behaviour - also intermittently. Did you find a resolution?

    Here is the stack trace I'm seeing:

    System.NullReferenceException: Object reference not set to an instance of an object.
    Server stack trace:
       at Microsoft.Crm.Sandbox.SandboxCallbackService.ProcessException(Exception e, SandboxSdkClient client)
       at Microsoft.Crm.Sandbox.SandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object sandboxTraceSettingsObj)
       at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Microsoft.Crm.Sandbox.ISandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object traceSettings)
       at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(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, List`1 linkLookups, String& pagingCookie, Boolean& moreRecords)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List`1 linkLookups)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression)
       at Microsoft.Xrm.Sdk.Linq.QueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
       at DHP_Domain.SystemSetting.GetSetting(IOrganizationService service, Setting setting)
       at DHP_Domain.NotifyAzure.SendNotification(IOrganizationService service, AzureNoficationEvent eventType, EntityReference entityRef, Entity sourceEntity)
       at DHP_Plugins.Memberships.PostContactUpdatesToAzure.Execute(IServiceProvider serviceProvider)
  • Suggested answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Exceptions in Retrieve and RetrieveMultiple thrown by internal CRM mechanisms

    Hi Mateusz,

    Based on the data you shared i think your conclusions point in the right direction - error is happening at a CRM Platform level.

    Since the issue happens intermittently - maybe this could be related to the data itself that is being retrieved. (some records are in a faulty state while others are not) but this is just a guess.

    As this is CRM Online, I suggest reaching out directly to MS Support for assistance as they have access to the platform and can see more details around this error. Probably this might be your fastest way for solving the issue.

    Hope this helps,

    Radu

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans