web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

System.Runtime.Serialization.SerializationException Error

(0) ShareShare
ReportReport
Posted on by 445

Hello Experts,

im getting the Error "System.Runtime.Serialization.SerializationException:" in my Custom Workflow Step.

Did anyone know a solution?

This is my code:

                if (maschinenringstring != null)
                {

                    QueryExpression maschinenringquery = new QueryExpression("account");
                    maschinenringquery.ColumnSet = new ColumnSet(true);
                    maschinenringquery.Criteria.AddCondition("name", ConditionOperator.Like, maschinenringstring);
                    maschinenringquery.Criteria.AddCondition("businesstypecode", ConditionOperator.Equal, 4);

                    // query ausführen
                    EntityCollection retrievemaschinenring = service.RetrieveMultiple(maschinenringquery);

                    if (retrievemaschinenring.Entities.Count == 1)
                    {
                        Entity MaschinenringRef = retrievemaschinenring.Entities[0];
                        Maschinenring.Set(executionContext, new EntityReference("account", MaschinenringRef.Id));
                        tracingService.Trace("Maschinenring gefunden und zugeordnet");
                    }
                    else
                    {
                        tracingService.Trace("Keinen Maschinenring gefunden");
                    }
                }


Kind Regards,
Léon

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please provide full code? This code looks good.

    Additionally can you please tell on what line your code fails?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Leon,

    Could you please try with this . I just modified the query expression part , let me know which line you are getting error after modifying this.

                    if (maschinenringstring != null)
                    {
                        ConditionExpression condition1 = new ConditionExpression();
                        ConditionExpression condition2 = new ConditionExpression();
                        FilterExpression filter1 = new FilterExpression();
                        filter1.FilterOperator = LogicalOperator.Or;
    
    
    
                        condition1.AttributeName = "name";
                        condition1.Operator = ConditionOperator.Like;
                        condition1.Values.Add("%" + maschinenringstring + "%");
                        filter1.Conditions.Add(condition1);
    
                        condition2.AttributeName = "businesstypecode";
                        condition2.Operator = ConditionOperator.Equal;
                        condition2.Values.Add(4);
                        filter1.Conditions.Add(condition2);
    
                        QueryExpression maschinenringquery = new QueryExpression();
                        maschinenringquery.Criteria.AddFilter(filter1);
                        maschinenringquery.EntityName = "account";
                        maschinenringquery.ColumnSet = new ColumnSet();
                        maschinenringquery.ColumnSet.AddColumns("name", "accountid", "accountnumber", "statuscode");
                        EntityCollection retrievemaschinenring = service.RetrieveMultiple(maschinenringquery);
    
                        if (retrievemaschinenring.Entities.Count == 1)
                        {
                            Entity MaschinenringRef = retrievemaschinenring.Entities[0];
                            Maschinenring.Set(executionContext, new EntityReference("account", MaschinenringRef.Id));
                            tracingService.Trace("Maschinenring gefunden und zugeordnet");
                        }
                        else
                        {
                            tracingService.Trace("Keinen Maschinenring gefunden");
                        }
                    }
  • BlackBeard Profile Picture
    445 on at

    Hello,

    this is the complete code:

        /// </summary>    
        public sealed class SelectMaschinenring : WorkFlowActivityBase
        {
    
            //create Trace Service
            private ITracingService tracingService;
    
            #region Properties 
            //Property for Entity mrd_abrufschein
            [RequiredArgument]
            [Input("Maschinenring")]
            public InArgument<string> maschinenringstring { get; set; }
            #endregion
    
    
    
            private IOrganizationService service { get; set; }
    
            /// <summary>
            /// Executes the WorkFlow.
            /// </summary>
            /// <param name="crmWorkflowContext">The <see cref="LocalWorkflowContext"/> which contains the
            /// <param name="executionContext" > <see cref="CodeActivityContext"/>
            /// </param>       
            /// <remarks>
            /// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
            /// The WorkFlow's Execute method should be written to be stateless as the constructor
            /// is not called for every invocation of the WorkFlow. Also, multiple system threads
            /// could execute the WorkFlow at the same time. All per invocation state information
            /// is stored in the context. This means that you should not use global variables in WorkFlows.
            /// </remarks>
            public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
            {
    
                // Create the tracing service
                tracingService = executionContext.GetExtension<ITracingService>();
                if (tracingService == null)
                {
                    throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");
                }
                tracingService.Trace("Entered SelectMaschinenring.Excecute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
                    executionContext.ActivityInstanceId,
                    executionContext.WorkflowInstanceId);
    
                // Create the context
                IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
    
                if (context == null)
                {
                    throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
                }
    
                tracingService.Trace("SelectMaschinenring.Execute(), Correlation Id: {0}, Initiating User: {1}",
                    context.CorrelationId,
                    context.InitiatingUserId);
    
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                service = serviceFactory.CreateOrganizationService(context.UserId);
    
                try
                {
                    if (maschinenringstring != null)
                    {
    
                        QueryExpression maschinenringquery = new QueryExpression("account");
                        maschinenringquery.ColumnSet = new ColumnSet(true);
                        maschinenringquery.Criteria.AddCondition("name", ConditionOperator.Like, maschinenringstring);
                        maschinenringquery.Criteria.AddCondition("businesstypecode", ConditionOperator.Equal, 4);
    
                        // query ausführen
                        EntityCollection retrievemaschinenring = service.RetrieveMultiple(maschinenringquery);
    
                        if (retrievemaschinenring.Entities.Count == 1)
                        {
                            Entity MaschinenringRef = retrievemaschinenring.Entities[0];
                            Maschinenring.Set(executionContext, new EntityReference("account", MaschinenringRef.Id));
                            tracingService.Trace("Maschinenring gefunden und zugeordnet");
                        }
                        else
                        {
                            tracingService.Trace("Keinen Maschinenring gefunden");
                        }
                    }                
    
    
                }
                catch (Exception ex)
                {
                    tracingService.Trace("Fehler in Methode SelectMaschinenring " + ex.Message);
    
                }
    
            }
    
            // Output aus Class Provisionsdaten
            [Output("Maschinenring")]
            [ReferenceTarget("account")]
            public OutArgument<EntityReference> Maschinenring { get; set; }
            
        }


  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Can you try setting null on the output parameter on the if part where the retrieved account is not euals 1 and see if it works?

    =======

    if (retrievemaschinenring.Entities.Count == 1)

                       {

                           Entity MaschinenringRef = retrievemaschinenring.Entities[0];

                           Maschinenring.Set(executionContext, new EntityReference("account", MaschinenringRef.Id));

                           tracingService.Trace("Maschinenring gefunden und zugeordnet");

                       }

                       else

                       {

                           Maschinenring.Set(executionContext, null);

                           tracingService.Trace("Keinen Maschinenring gefunden");

                       }

    ==============

    Also, could you please share a screenshot of the error messahe, it looks like it is occuring on the workflow itself and not this workflow activity.

    Hope this helps.

  • BlackBeard Profile Picture
    445 on at

    so i tried to convert the variable in a string.

    Now the error message is another one.

    Is my InArgument empty?

    I checked the Input in my Workflow and it was filled.

    Entered SelectMaschinenring.Excecute(), Activity Instance Id: 1, Workflow Instance Id: 9f1169ea-5407-41ba-96f9-ca70fd068cc8

    SelectMaschinenring.Execute(), Correlation Id: 1caad332-665b-459c-8f2e-c1c5e50b12db, Initiating User: a1223db7-c8a1-e611-80ea-5065f38b1311

    System.Activities.InArgument`1[System.String]

    System.Activities.InArgument`1[System.String]

    Keinen Maschinenring gefunden

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Could you please elaborate " i tried to convert the variable in a string." you changed the input parameter?

    You are getting this message after adding the below line?

     Maschinenring.Set(executionContext, null);

    Screenshot of the error will help!

  • BlackBeard Profile Picture
    445 on at

    No, the Line wont work...

    If i trace the maschinenringstring variable i only get System.Activities.InArgument`1[System.String] but not the Text in the String.

    Kind Regards

    Léon

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to replace line

    maschinenringquery.Criteria.AddCondition("name", ConditionOperator.Like, maschinenringstring);

    with line

    maschinenringquery.Criteria.AddCondition("name", ConditionOperator.Like, maschinenringstring.Get(executionContext));

  • Verified answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Andrew Butenko is correct. You need to get the string inside InArgument variable first:

    var condition = maschineringstring.Get(executionContext);

    if (!string.IsNullOrEmpty(condition))

                   {

                       QueryExpression maschinenringquery = new QueryExpression("account");

                       maschinenringquery.ColumnSet = new ColumnSet(true);

                       maschinenringquery.Criteria.AddCondition("name", ConditionOperator.Like, condition);

                       maschinenringquery.Criteria.AddCondition("businesstypecode", ConditionOperator.Equal, 4);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans