2011-10-24 68 views
1

我收到「指定的轉換無效」。嘗試更新自定義實體上的自定義字段的OptionSetValue屬性時發生異常。無法更新CRM 2011定製實體上的OptionSetValue字段

這工作:

data = new Xrm.Xyz_data() 
{ 
    Xyz_dataId = (Guid)entity["xyz_dataId"], 
    // Xyz_dataStatus = new OptionSetValue(5), 
    Xyz_IsSyncReqd = true 
}; 

service.Update(data); 

但取消對OptionSetValue線,並拋出這個異常:

System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Specified cast is not valid. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault). 

有了這個堆棧跟蹤:

Server stack trace: 
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity) 
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.UpdateCore(Entity entity) 
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Update(Entity entity) 

回答

0

所以我終於弄清楚發生了什麼事。我打開服務器端調試使用相同的註冊表設置,如CRM 4.0:

Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM] 
"TraceEnabled"=dword:00000001 
"TraceCategories"="*:Error" 
"TraceCallStack"=dword:00000001 
"TraceRefresh"=dword:00000001 

我重新我的測試中失敗,並發現了這個錯誤:

[2011-10-24 18:19:37.990] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread: 14 |Category: Platform |User: 00000000-0000-0000-0000-000000000000 |Level: Error | ExceptionConverter.ConvertMessageAndErrorCode 
    at ExceptionConverter.ConvertMessageAndErrorCode(Exception exception, Int32& errorCode) 
    at ExceptionConverter.ToSingleFaultOther(Exception exception) 
    at ExceptionConverter.ToSingleFaultUntyped(Exception exception) 
    at ExceptionConverter.ConvertToFault(Exception exception) 
    at ExceptionConverter.TryConvertToFaultExceptionInternal(Exception exception, Boolean createNewFaultException, FaultException`1& faultException) 
    at FaultHelper.ConvertToFault(Exception exception) 
    at OrganizationSdkServiceInternal.Update(Entity entity, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType) 
    at 
    at SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) 
    at DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 
    at ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) 
    at ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) 
    at MessageRpc.Process(Boolean isOperationContextSet) 
    at ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) 
    at ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) 
    at ChannelHandler.AsyncMessagePump(IAsyncResult result) 
    at AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 
    at AsyncResult.Complete(Boolean completedSynchronously) 
    at ReceiveItemAndVerifySecurityAsyncResult`2.InnerTryReceiveCompletedCallback(IAsyncResult result) 
    at AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 
    at AsyncResult.Complete(Boolean completedSynchronously) 
    at AsyncQueueReader.Set(Item item) 
    at InputQueue`1.Dispatch() 
    at ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
    at IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
    at _IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
>System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #9F125FAE: System.InvalidCastException: Specified cast is not valid. 
> at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.IntentionalRethrow(Exception chainException, Exception originalException) 
> at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.RethrowRecommended(Exception chainException, Exception originalException) 
> at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception exceptionToHandle) 
> at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception exceptionToHandle) 
> at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory) 
> at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) 
> at Common.Services.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) 
> at XYZ.CRM.Common.Services.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) 
> at XYZ.CRM.Plugin.Common.PluginBase.OnError(Exception ex) 
> at XYZ.CRM.Plugin.Common.PluginBase.Execute(IServiceProvider serviceProvider) 
> at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context) 
> at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context) 

而且因爲我是通過調試我的插件一個單元測試,我意識到當插件更新這些字段時,另一個插件被解僱了,而且這個插件顯然導致了一個異常。但更糟糕的是,異常處理程序正在導致另一個異常,即得到返回,掩蓋了真正的異常。我通過吃掉異常處理程序可能拋出的任何異常來測試一個非常簡單的修復方法,現在它工作的很好!現在發現爲什麼我的其他插件失敗了...

0

這看起來我的權利 - 我不使用它看起來像你正在做的早期界限,但你可以驗證數據上下文已經自從創建和發佈選項列表屬性後刷新了哪些內容?

如果這是一個內置狀態字段,您可能需要先執行更新,然後執行UpdateStateValueRequest。摘自CRM 2011 SDK -

 
#region How to update state value 
// Modify the state value label from Active to Open. 
// Create the request. 
UpdateStateValueRequest updateStateValue = new UpdateStateValueRequest 
{ 
    AttributeLogicalName = "statecode", 
    EntityLogicalName = Contact.EntityLogicalName, 
    Value = 1, 
    Label = new Label("Open", _languageCode) 
}; 

// Execute the request. 
_serviceProxy.Execute(updateStateValue); 

#endregion How to update state value 
相關問題