Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

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

$
0
0

This is the error from the plugin:


Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, 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">
  <ErrorCode>-2147220891</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>OperationStatus</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
    </KeyValuePairOfstringanyType>
    <KeyValuePairOfstringanyType>
      <d2p1:key>SubErrorCode</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>Object reference not set to an instance of an object.</Message>
  <Timestamp>2017-02-22T14:59:15.1047352Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>

[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

</TraceText>
</OrganizationServiceFault>

here is the code:

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

namespace

 RentSummary

{
/// <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") &&

                context.InputParameters[


"Target"] is Entity)

            {

               


// Obtain the target entity from the input parameters.


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

               


//</snippettenancyreferencenumberplugin>

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


//{


// An mvh_name attribute should not already exist because


// it is system generated.


Random rndgen = new Random();

                entity.Attributes.Add(


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

               


//}


            }

        }

    }

}


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>