First Plugin Error: Object reference not set to an instance of an object RRS feed

  • Question

  • This is the error from the plugin:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Object reference not set to an instance of an object.Detail:
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
      <Message>Object reference not set to an instance of an object.</Message>
      <InnerFault i:nil="true" />

    [RentSummary: RentSummary.PluginEntryPoint]
    [fb2e8242-0ff9-e611-8130-005056bd54af: RentSummary.PluginEntryPoint: Update of RD]
    Entered RentSummary.PluginEntryPoint.Execute(), Correlation Id: 09aa14e7-8608-4fbc-b77a-39ae7e7a31bb, Initiating User: 66d31042-d5e3-e611-80de-005056bd45eb
    Exiting RentSummary.PluginEntryPoint.Execute(), Correlation Id: 09aa14e7-8608-4fbc-b77a-39ae7e7a31bb, Initiating User: 66d31042-d5e3-e611-80de-005056bd45eb


    here is the code:

    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;



    /// <summary>
    /// PluginEntryPoint plug-in.
    /// This is a generic entry point for a plug-in class. Use the Plug-in Registration tool found in the CRM SDK to register this class, import the assembly into CRM, and then create step associations.
    /// A given plug-in can have any number of steps associated with it.
    /// </summary>   

    public class PluginEntryPoint : PluginBase

    /// <summary>
    /// Initializes a new instance of the <see cref="PluginEntryPoint"/> class.
    /// </summary>
    /// <param name="unsecure">Contains public (unsecured) configuration information.</param>
    /// <param name="secure">Contains non-public (secured) configuration information.
    /// When using Microsoft Dynamics CRM for Outlook with Offline Access,
    /// the secure string is not passed to a plug-in that executes while the client is offline.</param>

    public PluginEntryPoint(string unsecure, string secure): base(typeof(PluginEntryPoint))

            {// TODO: Implement your custom configuration handling.
    /// <summary>
    /// Main entry point for he business logic that the plug-in is to execute.
    /// </summary>

    /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the

    /// <see cref="IPluginExecutionContext"/>,

    /// <see cref="IOrganizationService"/>

    /// and <see cref="ITracingService"/>

    /// </param>

    /// <remarks>

    /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.

    /// The plug-in's Execute method should be written to be stateless as the constructor

    /// is not called for every invocation of the plug-in. Also, multiple system threads

    /// could execute the plug-in at the same time. All per invocation state information

    /// is stored in the context. This means that you should not use global variables in plug-ins.

    /// </remarks>

    protected override void ExecuteCrmPlugin(LocalPluginContext localContext)



    if (localContext == null)



    throw new ArgumentNullException("localContext");




    IPluginExecutionContext context = localContext.PluginExecutionContext;


    IOrganizationService service = localContext.OrganizationService;


    ITracingService tracingService = localContext.TracingService;


    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)localContext.ServiceProvider.GetService(typeof(IOrganizationServiceFactory));


    if (context.InputParameters.Contains("Target") &&


    "Target"] is Entity)



    // Obtain the target entity from the input parameters.

    Entity entity = (Entity)context.InputParameters["Target"];



    //if (entity.LogicalName == "RD")


    // An mvh_name attribute should not already exist because

    // it is system generated.

    Random rndgen = new Random();


    "RD_name", rndgen.Next().ToString());







    Wednesday, February 22, 2017 3:06 PM

All replies

  • I would suggest you to check whether context is not null as well before you call the input parameters. 

    Also start adding tracing after each line so you can check the plugin trace log (you have to enable it first) to know where it broke.

    Sachith Chandrasiri

    Thursday, February 23, 2017 12:18 AM
  • What is SDK Message that is being used to register this plugin in ?

    Note that not all requests contain a Target property that is of type Entity, so you have to look at each request or response. For example, DeleteRequest has a Target property, but its type is EntityReference. 


    • Proposed as answer by Makarand Keer Monday, February 27, 2017 3:46 AM
    Friday, February 24, 2017 7:39 PM
  • I think null check on

    • context.InputParameters["Target"]
    • entity.Attribute

    is missing...



    Monday, February 27, 2017 1:40 PM