About the author

J Sawyer is a developer based in Houston, TX who absolutely loves to write code. After spending 9 years at Microsoft, he moved on to other things and is currently the Lead Developer for the RealTime Data Management team at Logica US. He spends his days building Really Cool Things around StreamInsight and having a blast doing it.

He has been involved with HDNUG, one of the oldest and largest .NET-focused user groups in the US, since its inception in 2001 and has watched it grow from 5-10 technologists meeting around a conference table to a thriving community of over 5000 with regular meeting attendance averaging 100 attendees. He currently serves as the Vice President. You can join him at HDNUG on the second Thursday of every month at the Houston Microsoft office.

He also loves to ride his Yamaha FZ1. And sometimes his Ninja 650. And also his Honday XR-400 dirt bike. But he doesn't code and ride at the same time. That would be bad.

Serialization and StreamInsight Adapter Config Classes

September 1, 2011 10:05 AM

It is essential that you mark your StreamInsight adapter configuration classes with either the [Serializable()] or [DataContract()] attributes. Keep in mind that the StreamInsight engine can be run either in process or remotely … and, if remote, these classes will have to be serialized on the wire. The serializable attribute is easier, but the DataContract attribute - through the [DataMember()] and the [IgnoreDataMember()] attributes - allows you to be more explicit in specifying which members actually go on the wire. I looked (quickly) and didn’t see this document but that doesn’t mean that it isn’t.

Now … what can happen if you don’t do this? Bad things. This happened to me yesterday and simply reinforced why I shave my head (so I can’t rip my hair out). So … everything had been working fine. I was making some changes to an adapter to try to resolve a Heisenbug caused by a race condition during the adapter tear down (I’ll discuss some of these challenges later, I think). When I went to run to test, I started running into exceptions when starting the query. It was an XmlException with the message:

Name cannot begin with the '<' character, hexadecimal value 0x3C.

Huh? I checked through everything and there were no members that began with a “<”. In fact, the C# compiler won’t let you do this, even if you use the “@” character (rightfully so … I mean, why on earth would you do that??). Examining the full stack trace, I could see that it was happening during the stream creation while serializing something. Once I loaded the debug symbols, I found that the offending member name was “<LogName>k__BackingField”, which certainly does begin with a “<”. Of course, there was no member that I declared in the code … there’s no way that I would even try to declare such a thing. It turns out, however, that the C# compiler will declare the backing fields for automatic properties like this and, for some reason, it chose yesterday to start blowing up on me. I finally found that the configuration class for a specific adapter was not marked as serializable (and I know better than this) and, once I changed it, all worked just fine.

I gotta tell you, I do so hate these mysterious errors.

Tags:

StreamInsight