Our example must read all values from a dataset and then calculate the statistical moment over all values. This is why we must store the list of values in .NET lists. At the moment, native serialization used internally in CLR aggregates fail. This is because .NET lists are too complicated for the simple method of serialization. Consequently, the first adjustment in our source code is to implement the IBinarySerializable interface. Furthermore, the decoration of the SqlUserDefinedAggregate attribute also has to be changed. The following section of the code shows what to do here:
//original code generated by Visual Studio[Serializable][SqlUserDefinedAggregate(Format.Native)]public struct StatMoment//adjustments ...