2011-10-24 2 views
1

Je reçois un "Cast spécifié n'est pas valide". Exception lors de la tentative de mise à jour d'un attribut OptionSetValue d'un champ personnalisé sur une entité personnalisée.Impossible de mettre à jour le champ OptionSetValue sur CRM 2011 Entité personnalisée

Cela fonctionne:

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

service.Update(data); 

Mais Décommentez la ligne OptionSetValue et il lance cette exception:

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

Avec cette trace de la pile:

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) 

Répondre

0

Alors j'ai finalement compris ce qui se passait. Je me suis tourné le débogage côté serveur en utilisant les mêmes paramètres de registre comme 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 

Je rediffusé mon test qui a été un échec, et a trouvé cette erreur:

[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) 

Et depuis que je suis débogage mon plugin via un test unitaire, je me suis rendu compte qu'un autre plugin était déclenché quand ces champs étaient mis à jour par mon plugin, et que ce plugin provoquait apparemment une exception. Mais pire encore, le gestionnaire d'exceptions provoquait une autre exception, qui était retournée, masquant la véritable exception. J'ai testé un correctif très simple en mangeant toutes les exceptions que le gestionnaire d'exception pourrait lancer, et cela fonctionne très bien maintenant! Maintenant, pour découvrir pourquoi mon autre plugin échoue ...

0

Cela semble juste pour moi - Je n'utilise pas la méthode "early bound", ce que vous semblez faire, mais pouvez-vous vérifier que le contexte fr actualisé depuis que l'attribut picklist a été créé et publié?

S'il s'agit d'un champ d'état intégré, vous devrez probablement effectuer la mise à jour, puis effectuer une mise à jour UpdateStateValueRequest. Extrait de 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 
Questions connexes