2011-10-24 21 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 

私は失敗していた私のテストをreran、このエラーを検出しました:

[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

右私には見えることを - あなたがやっているように見える初期バインディングは使用しませんが、データコンテキストがpicklist属性が作成されて公開されて以来、リフレッシュされましたか?

これが組み込みの状態フィールドの場合は、まず更新を行い、次に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 
関連する問題