0
votes

I've added a custom attribute ("custom_contacttype") to the Contact entity. This attribute is of type picklist which is comprised of seven values. I'm developing using Advanced Developer Extensions for Microsoft Dynamics CRM against CRM 4.0. After I set the value for this attribute and call SaveChanges() I get "Object reference not set to an instance of an object." error. I've been battling this one for a while. What am I doing wrong? Below is my code:

var crm = new CrmDataContext(context.Connection);

var saveContact = crm.GetEntities("contact").Where(p => p.GetPropertyValue<Guid>      ("contactid") == contact.Id.Value).Single();

saveContact.SetPropertyValue("custom_contacttype", 2, typeof(Picklist));

crm.UpdateObject(saveContact);
crm.SaveChanges();

Trace Log from CRM Server: [2011-07-01 16:39:33.7] Process: w3wp |Organization:f827deb3-c6cc-df11-bc07-005056887b79 |Thread: 8 |Category: Platform.Sdk |User: 822138f1-c574-e011-9dca-005056887b79 |Level: Error | PluginStep.Execute at PluginStep.Execute(PipelineExecutionContext context) at Pipeline.Execute(PipelineExecutionContext context) at MessageProcessor.Execute(PipelineExecutionContext context) at InternalMessageDispatcher.Execute(PipelineExecutionContext context) at ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId) at CrmServiceInternal.Update(String namespaceName, BusinessEntityBase entity, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId) at CrmService.Update(BusinessEntity entity) at RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at LogicalMethodInfo.Invoke(Object target, Object[] values) at WebServiceHandler.Invoke() at WebServiceHandler.CoreProcessRequest() at SyncSessionlessHandler.ProcessRequest(HttpContext context) at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at ApplicationStepManager.ResumeSteps(Exception error) at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr) at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)

Web Service Plug-in failed in SdkMessageProcessingStepId: {27DF4121-19BC-DF11-A90E-005056887B79}; EntityName: contact; Stage: 10; MessageName: Update; AssemblyName: AccessCRM.ChangeLogContactData, AccessCRM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a030c130976783ab; ClassName: AccessCRM.ChangeLogContactData; Exception: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at AccessCRM.PluginUtilities.GetStringValueFromProperty(Property p) at AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext context) at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context) . [2011-07-01 16:39:33.7] Process: w3wp |Organization:f827deb3-c6cc-df11-bc07-005056887b79 |Thread: 8 |Category: Platform.Sdk |User: 822138f1-c574-e011-9dca-005056887b79 |Level: Error | PluginExecutionExceptionHandler.Handle at PluginExecutionExceptionHandler.Handle(Stream from, Stream to, Exception exception) at CompositeSoapExtensionExceptionHandler.Handle(Stream to, Stream from, Exception exception) at CrmAuthenticationSoapExtensionBase.ProcessMessage(SoapMessage message) at SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException) at SoapServerProtocol.WriteException(Exception e, Stream outputStream) at WebServiceHandler.WriteException(Exception e) at WebServiceHandler.Invoke() at WebServiceHandler.CoreProcessRequest() at SyncSessionlessHandler.ProcessRequest(HttpContext context) at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at ApplicationStepManager.ResumeSteps(Exception error) at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr) at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType) CrmSoapExtension detected InvalidPluginExecutionException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Microsoft.Crm.Sdk.InvalidPluginExecutionException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at AccessCRM.PluginUtilities.GetStringValueFromProperty(Property p) at AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext context) at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context) --- End of inner exception stack trace --- at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId) at Microsoft.Crm.Sdk.CrmServiceInternal.Update(String namespaceName, BusinessEntityBase entity, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId) at Microsoft.Crm.Sdk.Crm2007.CrmService.Update(BusinessEntity entity) --- End of inner exception stack trace ---

1

1 Answers

1
votes

Looking at the stack trace, the error is actually being thrown in a plugin, not in the code you have pasted above. Look at this line in particular:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. 
at AccessCRM.PluginUtilities.GetStringValueFromProperty(Property p)
at AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext context)

You'd need to post up the code for that plugin for us to have another look.

Alternatively use Remote Debugging to debug this yourself.