locked
Dynamic.ExpandoObjet s not marked as serializable RRS feed

  • Question

  • Hi i am using the below piece of code in C# helper class to convert the SQL response to dynamic object and call this from Orchestration .. I marked the class as  [Serializable].. I am able to read the values from the object but i am getting the exception when i am send in the message out.. 

    'System.Dynamic.ExpandoObject' in Assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

    private void CreateDynamicObj(DataTable _objDT)
            {
                _objDynamic = new List<dynamic>();
    
                foreach (var item in _objDT.AsEnumerable())
                {
                    // Expando objects are IDictionary<string, object>
                    IDictionary<string, object> dn = new ExpandoObject();
                    foreach (var column in _objDT.Columns.Cast<DataColumn>())
                    {
                        dn[column.ColumnName] = item[column];
                    }
                    _objDynamic.Add(dn);
                }
            }

    Tuesday, April 5, 2016 6:04 PM

Answers

  • You can use a static method on helper class. How? Refer: Use static functions to avoid atomic scope in orchestration

    private static void CreateDynamicObj(DataTable _objDT)
            {
                _objDynamic = new List<dynamic>();
    
                foreach (var item in _objDT.AsEnumerable())
                {
                    // Expando objects are IDictionary<string, object>
                    IDictionary<string, object> dn = new ExpandoObject();
                    foreach (var column in _objDT.Columns.Cast<DataColumn>())
                    {
                        dn[column.ColumnName] = item[column];
                    }
                    _objDynamic.Add(dn);
                }
            }

    If a class contains only static methods, then you can change the class also to static and then you do not need to use [Serializable] for a static class.  Make sure to GAC the assembly and restart host instance before testing it. So in your expression shape you will have code like:

    <your variable> = %namespace%.method(parameter)

    For reference see also this thread .


    Rachit Sikroria (Microsoft Azure MVP)

    Tuesday, April 5, 2016 6:45 PM
    Moderator

All replies

  • Hi,

    Thank you for posting on MSDN forum.

    Is your .NET helper class marked as serializable? If not, you should place the Expression shape (that calls your .NET class method) inside a Scope shape with its Transaction Type set as Atomic.

    Similar kind of issue has been discussed in below thread,

    https://social.msdn.microsoft.com/Forums/en-US/714ab9af-2971-44e8-8aba-f83f867292bd/calling-external-assembly-problem-systemdatasqlclientsqlconnection-is-not-marked-as?forum=biztalkgeneral


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Tuesday, April 5, 2016 6:20 PM
    Moderator
  • I did mark my class as  [Serializable] but still getting the issue 
    Tuesday, April 5, 2016 6:35 PM
  • You can use a static method on helper class. How? Refer: Use static functions to avoid atomic scope in orchestration

    private static void CreateDynamicObj(DataTable _objDT)
            {
                _objDynamic = new List<dynamic>();
    
                foreach (var item in _objDT.AsEnumerable())
                {
                    // Expando objects are IDictionary<string, object>
                    IDictionary<string, object> dn = new ExpandoObject();
                    foreach (var column in _objDT.Columns.Cast<DataColumn>())
                    {
                        dn[column.ColumnName] = item[column];
                    }
                    _objDynamic.Add(dn);
                }
            }

    If a class contains only static methods, then you can change the class also to static and then you do not need to use [Serializable] for a static class.  Make sure to GAC the assembly and restart host instance before testing it. So in your expression shape you will have code like:

    <your variable> = %namespace%.method(parameter)

    For reference see also this thread .


    Rachit Sikroria (Microsoft Azure MVP)

    Tuesday, April 5, 2016 6:45 PM
    Moderator
  • Why can't you use a Map?
    Tuesday, April 5, 2016 7:04 PM
    Moderator