设置 PickList 类型的属性值时更新动态实体时出错
我已向联系人实体添加了自定义属性(“custom_contacttype”)。该属性属于选项列表类型,由七个值组成。我正在针对 CRM 4.0 使用 Microsoft Dynamics CRM 的高级开发人员扩展进行开发。设置此属性的值并调用 SaveChanges() 后,我得到“对象引用未设置到对象的实例”。错误。我已经和这个问题斗争了一段时间了。我做错了什么?下面是我的代码:
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();
来自 CRM 服务器的跟踪日志: [2011-07-01 16:39:33.7] 进程:w3wp |组织:f827deb3-c6cc-df11-bc07-005056887b79 |线程:8 |类别:Platform.Sdk |用户: 822138f1-c574-e011-9dca-005056887b79 |级别:错误|插件步骤.执行 在 PluginStep.Execute(PipelineExecutionContext 上下文) 在 Pipeline.Execute(PipelineExecutionContext 上下文) 在 MessageProcessor.Execute(PipelineExecutionContext 上下文) 在InternalMessageDispatcher.Execute(PipelineExecutionContext上下文) 在ExternalMessageDispatcher.Execute(字符串messageName,Int32primaryObjectTypeCode,Int32 secondaryObjectTypeCode,PropertyBag字段,CorrelationTokencorrelationToken,CallerOriginTokenoriginToken,UserAuthuserAuth,GuidcallerId) 在 CrmServiceInternal.Update(字符串名称空间名称、BusinessEntityBase 实体、CorrelationToken correlationToken、CallerOriginToken originToken、UserAuth userAuth、Guid callerId) 在 CrmService.Update(BusinessEntity 实体) 在 RuntimeMethodHandle._InvokeMethodFast(对象目标,Object[] 参数,SignatureStruct& sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner) 在 RuntimeMethodInfo.Invoke(对象 obj、BindingFlags invokeAttr、Binder 活页夹、Object[] 参数、CultureInfo 区域性、布尔值skipVisibilityChecks) 在 RuntimeMethodInfo.Invoke(对象 obj、BindingFlags invokeAttr、Binder 绑定器、Object[] 参数、CultureInfo 区域性) 在 LogicalMethodInfo.Invoke(对象目标,对象[]值) 在 WebServiceHandler.Invoke() 在 WebServiceHandler.CoreProcessRequest() 在 SyncSessionlessHandler.ProcessRequest(HttpContext 上下文) 在 CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean&completedSynchronously) 在ApplicationStepManager.ResumeSteps(异常错误) 在 HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext 上下文,AsyncCallback cb,对象 extraData) 在 HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) 在 HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr) 在 ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
SdkMessageProcessingStepId 中的 Web 服务插件失败:{27DF4121-19BC-DF11-A90E-005056887B79};实体名称:联系人;阶段:10;消息名称:更新;程序集名称:AccessCRM.ChangeLogContactData,AccessCRM,版本=1.0.0.0,文化=中性,PublicKeyToken=a030c130976783ab;类名:AccessCRM.ChangeLogContactData;异常:未处理的异常:System.NullReferenceException:未将对象引用设置为对象的实例。 在 AccessCRM.PluginUtilities.GetStringValueFromProperty(属性 p) 在 AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext 上下文) 。 [2011-07-01 16:39:33.7] 进程:w3wp |组织:f827deb3-c6cc-df11-bc07-005056887b79 |线程:8 |类别:Platform.Sdk |用户: 822138f1-c574-e011-9dca-005056887b79 |级别:错误| PluginExecutionExceptionHandler.Handle at PluginExecutionExceptionHandler.Handle(Stream from, Stream to, Exception异常) 在 CompositeSoapExtensionExceptionHandler.Handle(流至、流自、Exception 异常) 在 CrmAuthenticationSoapExtensionBase.ProcessMessage(SoapMessage 消息) 在 SoapMessage.RunExtensions(SoapExtension[] 扩展,布尔 throwOnException) 在 SoapServerProtocol.WriteException(异常 e,流输出流) 在WebServiceHandler.WriteException(异常e) 在 WebServiceHandler.Invoke() 在 WebServiceHandler.CoreProcessRequest() 在 SyncSessionlessHandler.ProcessRequest(HttpContext 上下文) 在 CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean&completedSynchronously) 在ApplicationStepManager.ResumeSteps(异常错误) 在 HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext 上下文,AsyncCallback cb,对象 extraData) 在 HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) 在 HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr) 在 ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType) CrmSoapExtension 检测到 InvalidPluginExecutionException: System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> Microsoft.Crm.Sdk.InvalidPluginExecutionException:未将对象引用设置为对象的实例。 ---> System.NullReferenceException:未将对象引用设置为对象的实例。 在 AccessCRM.PluginUtilities.GetStringValueFromProperty(属性 p) 在 AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext 上下文) --- 内部异常堆栈跟踪结束 --- 在 Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext 上下文) 在 Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(字符串 messageName、Int32 PrimaryObjectTypeCode、Int32 secondaryObjectTypeCode、PropertyBag 字段、CorrelationToken correlationToken、CallerOriginToken originToken、UserAuth userAuth、Guid callerId) 在 Microsoft.Crm.Sdk.CrmServiceInternal.Update(字符串命名空间名称、BusinessEntityBase 实体、CorrelationToken correlationToken、CallerOriginToken originToken、UserAuth userAuth、Guid callerId) 在 Microsoft.Crm.Sdk.Crm2007.CrmService.Update(BusinessEntity 实体) --- 内部异常堆栈跟踪结束 ---
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 ---
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看堆栈跟踪,错误实际上是在插件中引发的,而不是在您上面粘贴的代码中引发的。特别看看这一行:
您需要发布该插件的代码,以便我们再看一下。
或者使用远程调试自行调试。
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:
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.