Hi, I have problem with the List in Read method, in this line: sum += intermediateResult[i]; I have error:
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException: 
   at Concatenate.Terminate()
My list is still empty, I do not know how to properly write read method for the list:
Code:
[Serializable]
[SqlUserDefinedAggregate(
    Format.UserDefined, 
    MaxByteSize = 8000)
]
public class Concatenate : IBinarySerialize
{
    private List<double> intermediateResult;
    private int count;

    public void Init()
    {
        count = 0;
        this.intermediateResult = new List<double>();
    }

    public void Accumulate(double? value)
    {
        if (value != null)
        {
            this.intermediateResult.Add((double)value);
            count++;
        }
    }

    public void Merge(Concatenate other)
    {
    }

    public SqlDouble Terminate()
    {
        double sum = 0.0;
        for (int i = 0; i < this.count; i++)
            sum += intermediateResult[i];
        return new SqlDouble(suma);
    }

    public void Read(BinaryReader r)
    {
        count = r.ReadInt32();
       // for(int i=0; i<14; i++) 
       //     intermediateResult[i] = r.ReadDouble();
    }

    public void Write(BinaryWriter w)
    {
        w.Write(count);
        w.Write(intermediateResult.Count * sizeof(double));
    }
}
In sql server :
Code:
CREATE ASSEMBLY zzz AUTHORIZATION dbo
FROM 'C:\library.dll'
WITH PERMISSION_SET=SAFE
GO
CREATE AGGREGATE aaa(@value float) RETURNS float 
EXTERNAL NAME zzz.Concatenate
GO
SELECT dbo.aaa(height) as height FROM People