none
PublishNotification with string array content throws SerializationException RRS feed

  • Question

  • I have configured a ReceiveNotification activity to receive a string[] (array) as part of its Content property. When I use the workflow client API to publish a notification which includes a Content item that is of type string[], I get the following exception:

    System.Runtime.Serialization.SerializationException was unhandled by user code
      HResult=-2146233076
      Message=Type 'System.String[]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
      Source=Microsoft.Workflow.Common
      StackTrace:
           at Microsoft.Workflow.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
           at Microsoft.Workflow.Client.HttpGetResponseAsyncResult`1.End(IAsyncResult result)
           at Microsoft.Workflow.Client.ClientHelpers.SendRequest[T](HttpWebRequest request, T content)

    ....

    The code used to publish the notification is as follows:

     // publish notification
    client.PublishNotification(new WorkflowNotification()
    {
    	Properties =
    	{
    		{ "EventName", "Office Approval Decision" },
    		{ "OfficeId", workflowDto.OfficeID }
    	},
    	Content = new Dictionary<string, object>()
    	{
    		{ "Decision", workflowDto.Decision },
    		{ "Domains", workflowDto.Domains },
    	}
    });

    In the above code, workflowDto.Domains is of type string[].

    I understand how this problem can be solved when you directly control the serialization code, but in this case it is wrapped up inside the Microsoft.Workflow.Common.dll.

    Is this a bug, considering that string arrays are supported within workflows and the trusted surface?


    Thursday, May 30, 2013 1:24 AM

Answers

  • Try Collection<String> instead of String[]. I believe latter is not supported while former is


    Ravi Sekhar

    • Marked as answer by darianf Tuesday, June 4, 2013 2:00 AM
    Friday, May 31, 2013 10:02 AM

All replies

  • Try Collection<String> instead of String[]. I believe latter is not supported while former is


    Ravi Sekhar

    • Marked as answer by darianf Tuesday, June 4, 2013 2:00 AM
    Friday, May 31, 2013 10:02 AM
  • I got into a world of serialization pain with both String[] and Collection<String>. As Ravi points out, String[] is not supported (plenty of discussions as to the why's and wherefores out there on the web). However, I couldn't get Collection<String> to work either (maybe I did something dumb). In the end, I opted to serialize my string arrays to JSON and parse-out in the workflow.

    ...
    Content = new Dictionary<string, object>()
    {
        {"Decision", workflowDto.Decision },
        {"Domains", Newtonsoft.Json.JsonConvert.SerializeObject(workflowDto.Domains) }
    }

    In the workflow, you would need to receive the Domains argument as a string and then convert to DynamicValue using ParseDymanicValue to get access to the individual members.

    Sunday, June 2, 2013 7:41 PM
  • Thanks Ravi, Spaghetti Soup for your responses. I tried Collection<String> which did work for me.

    However, I may need to work with serialized or delimited strings as I want to assign directly to a mapped/external workflow variable and I could not successfully expose a variable of type Collection<String> as a mapped variable - it compiles and publishes without error but does not get persisted to the database. The database schema for WFInstanceManagementDB.dbo.MappedVariables has a Value column of type nvarchar(255) so I suspect there is only support for integers, strings and booleans.

    Tuesday, June 4, 2013 2:00 AM