.net - How do I add the SqlException type to a custom tracking participant? -


i'm getting following (intermittent) errors in workflow tracking:

"an error occurred while calling tracking participants causing instance aborted. see inner exception more details. innerexception message: type 'system.data.sqlclient.sqlexception' data contract name 'sqlexception:http://schemas.datacontract.org/2004/07/system.data.sqlclient' not expected. consider using datacontractresolver or add types not known statically list of known types - example, using knowntypeattribute attribute or adding them list of known types passed datacontractserializer."

my custom tracking participant looks 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 go resolving this?

also, there other types workflow might throw @ me haven't seen yet need handle in tracking participant?

found solution here: http://blogs.msdn.com/b/youssefm/archive/2009/06/05/introducing-a-new-datacontractserializer-feature-the-datacontractresolver.aspx

create custom dcr:

public class sharedtyperesolver : datacontractresolver {     public override bool tryresolvetype(type datacontracttype, type declaredtype, datacontractresolver knowntyperesolver, out xmldictionarystring typename, out xmldictionarystring typenamespace)     {             if (!knowntyperesolver.tryresolvetype(datacontracttype, declaredtype, null, out typename, out typenamespace))         {             xmldictionary dictionary = new xmldictionary();             typename = dictionary.add(datacontracttype.fullname);             typenamespace = dictionary.add(datacontracttype.assembly.fullname);         }         return true;     }       public override type resolvename(string typename, string typenamespace, type declaredtype, datacontractresolver knowntyperesolver)     {         return knowntyperesolver.resolvename(typename, typenamespace, declaredtype, null) ?? type.gettype(typename + ", " + typenamespace);     } } 

change dcs line in code:

datacontractserializer serializer = new datacontractserializer(record.gettype(), null, int32.maxvalue, false, false, null, new sharedtyperesolver() 

job done.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -