Friday 4 May 2012

Custom activity Expected non-empty Guid

When writing custom activity for dialog process, I was getting an error " Expected non-empty Guidif I don't set the Out Argument of EntityReference type. Though the custom activity code is executing fine, this error was coming from with the workflow engine, Here is the complete error message


Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Expected non-empty Guid.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147220989</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>CallStack</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">   at Microsoft.Crm.Exceptions.ThrowIfGuidEmpty(Guid parameter, String name)
   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Retrieve(String entityName, Guid id, ColumnSet columnSet, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>Expected non-empty Guid.</Message>
  <Timestamp>2012-05-03T16:44:39.8508813Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>
[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.RetrieveEntity]
[RetrieveEntity]
Entered ContactRelationshipDefinition.Execute(), Activity Instance Id: 149, Workflow Instance Id: 9d1eb654-1cf1-4e7b-b54f-0a523ab72dc1
ContactRelationshipDefinition.Execute(), Correlation Id: 00000000-0000-0000-0000-000000000000, Initiating User: 5efdf43e-0578-e111-a01e-00155d450361
Exiting ContactRelationshipDefinition.Execute(), Correlation Id: 00000000-0000-0000-0000-000000000000
</TraceText>
</OrganizationServiceFault>


Solution: Rather then not setting  EntityReference  out argument due to some condition, set it to null.
For example

protected override void Execute(CodeActivityContext context)
{
//outputParameterName is the outpurt parameter, if there are more then one the set all those to null as well.
     context.SetValue<EntitiyReference>(outPutParamenterName,null)

  //custom logic goes here
}

4 comments:

  1. i am also facing the same kind of issue when i am tring to insert the data in custome entity using CRM web service.

    ReplyDelete
  2. have you tried setting up out argument to null explicitly in plugin, this did the trick for me.

    ReplyDelete
  3. I have updated the post a bit, the point when I say set it to null it means to set the output parameter to null like context.SetValue(outPutParamenterName,null) and not like outPuteParameterName = null

    ReplyDelete