web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

2 plugin steps causing null reference exception in plugin.

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

I have a business scenario which requires two plugin steps to be registered on the same message and same entity, the first step will execute business logic and the second step will post the entire plugin context to Azure service bus queue. I have set the execution order for both of the steps. These are registered on the syn mode for create message and post operation .When i combine both the requirements to a single plugin it works without any problem .However when i separate them into two it fails with "object reference not set to an instance". I have also verified that the posting to Azure service bus queue is working fine.

Any help on this is appreciated.

*This post is locked for comments

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Did you try to debug your code and to check on which line you are getting this error ??

  • Verified answer
    nghieppham Profile Picture
    4,755 on at


    Hi Dathatreya,

    You need to use plugin log to trace the root cause. This "object reference not set to an instance" is a normal error for development, almost about the init object, you should to log or debug to check this problem.

    For this case, before you debug, you can set the order of the plugin first.

    Regards,

  • Community Member Profile Picture
    on at

    Yes I have tried debugging my code using the plugin profile but the error doesn't seem to be caught in the debug process .

  • Community Member Profile Picture
    on at

    Yes I have tried debugging my code using the plugin profile but the error doesn't seem to be caught in the debug process , below is the code which is causing the problem. This code seems to be working fine when i run this alone but fails when i run it along with the other plugin .

    public void SendToServiceBus(Guid serviceEndpointId)
            {
                IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)_serviceProvider.GetService(typeof(IServiceEndpointNotificationService));
                if (cloudService == null)
                    throw new InvalidPluginExecutionException("Failed to retrieve the cloudservice.");
                try
                {
                    _tracingService.Trace("Posting the execution context.");
                    string response = cloudService.Execute(new EntityReference("serviceendpoint", serviceEndpointId), _context);
                    if (!String.IsNullOrEmpty(response))
                    {
                        _tracingService.Trace("Response = {0}", response);
                    }
                    _tracingService.Trace("Done.");
                }
                catch (Exception e)
                {
                    _tracingService.Trace("Exception: {0}", e.ToString());
                    throw;
                }
            }


  • Daniel Wikell Profile Picture
    2,360 on at

    Is _context referring to a private variable in your plugin class? If so, this can potentially cause issues since plugin classes are not thread safe and the system might re-use a plugin instance to run the execute method rather than always creating a new. When this happens, the content of your private variables might suddenly change mid-execution.

    To make sure this is not what is causing your issues you should move over to passing along the variables to each function instead of relying on private variables.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans