I’m getting the following (intermittent) errors in my workflow tracking:
“An error occurred while
calling tracking participants causing
the instance to be aborted. See the
inner exception for more details.
InnerException Message: Type
‘System.Data.SqlClient.SqlException’
with data contract name
‘SqlException:http://schemas.datacontract.org/2004/07/System.Data.SqlClient’
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.”
My custom tracking participant looks something like this:
protected override void Track (TrackingRecord record, TimeSpan timeout)
{
StringWriter sw = null;
if (record == null) throw new ArgumentNullException("record");
if (timeout == null) throw new ArgumentNullException("timeout");
StringBuilder sb = new StringBuilder();
sw = new StringWriter(sb);
using (XmlTextWriter writer = new XmlTextWriter(sw) { Formatting = Formatting.Indented })
{
DataContractSerializer serializer = new DataContractSerializer(record.GetType());
serializer.WriteObject(writer, record);
writer.Flush();
writer.Close();
}
_logger.Log(sb.ToString());
}
How do I go about resolving this?
Also, are there any other types that workflow might throw at me that I haven’t seen yet but need to handle in my tracking participant?
Found the solution here: http://blogs.msdn.com/b/youssefm/archive/2009/06/05/introducing-a-new-datacontractserializer-feature-the-datacontractresolver.aspx
Create a custom DCR:
Change DCS line in my code:
Job done.