Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

System.Runtime.Serialization.SerializationException Error

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

  • Verified answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: System.Runtime.Serialization.SerializationException Error

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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: System.Runtime.Serialization.SerializationException Error

    Hello,

    Try to replace line

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

    with line

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

  • BlackBeard Profile Picture
    BlackBeard 445 on at
    RE: System.Runtime.Serialization.SerializationException Error

    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

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: System.Runtime.Serialization.SerializationException Error

    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
    BlackBeard 445 on at
    RE: System.Runtime.Serialization.SerializationException Error

    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

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: System.Runtime.Serialization.SerializationException Error

    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
    BlackBeard 445 on at
    RE: System.Runtime.Serialization.SerializationException Error

    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
    gdas Profile Picture
    gdas 50,085 on at
    RE: System.Runtime.Serialization.SerializationException Error

    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");
                        }
                    }
  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: System.Runtime.Serialization.SerializationException Error

    Hello,

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

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans