¿Por qué la relación de entidad CRM 2011 es nula en este código de complemento?

Este es un ejemplo funcional de un complemento que he escrito para CRM 2011. He creado un paso 'Crear' en la herramienta de registro de complementos para este complemento. Esto se ejecuta bien. También tengo un paso 'Actualizar' registrado para el complemento. Esto no se puede ejecutar porque el contacto principal devuelto es nulo. Estos pasos están registrados como asíncronos.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using System.IO;
using System.Net;

namespace CRMNewsletterPlugin
{
    public class NewsletterSignup : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));

            tracingService.Trace("Begin load");
            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
            {
                tracingService.Trace("We have a target.");
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                if (!entity.GetAttributeValue<bool>("new_receivesnewsletter"))
                {
                    try
                    {
                        //check if the account number exist
                        string emailAddress = entity.GetAttributeValue<string>("emailaddress1");
                        EntityReference primaryContact = entity.GetAttributeValue<EntityReference>("primarycontactid");

                        // UPDATE STEP FAILS HERE
                        if (primaryContact == null)
                        {
                            tracingService.Trace("Primary Contact is null");
                        }
                        Entity contact = service.Retrieve("contact", primaryContact.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(new string[] { "fullname" }));
                        string fullname = contact.GetAttributeValue<string>("fullname");
                        string name = entity.GetAttributeValue<string>("name");
                        WebRequest req = WebRequest.Create("http://localhost");
                        string postData = "cm-name=" + fullname + "&cm-ddurhy-ddurhy=" + emailAddress + "&cm-f-jddkju=" + name;
                        tracingService.Trace(postData);
                        byte[] send = Encoding.Default.GetBytes(postData);
                        req.Method = "POST";
                        req.ContentType = "application/x-www-form-urlencoded";
                        req.ContentLength = send.Length;
                        tracingService.Trace("Sending info");

                        Stream sout = req.GetRequestStream();
                        sout.Write(send, 0, send.Length);
                        sout.Flush();
                        sout.Close();
                        tracingService.Trace("Info sent");
                        WebResponse res = req.GetResponse();
                        StreamReader sr = new StreamReader(res.GetResponseStream());
                        string returnvalue = sr.ReadToEnd();
                        tracingService.Trace(returnvalue);

                        entity.Attributes["new_receivesnewsletter"] = true;
                        service.Update(entity);
                        tracingService.Trace("Newsletter field set");

                    }
                    catch (FaultException ex)
                    {
                        throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                    }

                }
            }

        }
    }//end class
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta