.netsql-serversqlclruser-defined-aggregate

Msg 6558: CREATE AGGREGATE failed because type 'Concatenate' does not conform to UDAGG specification


I've created a SQLCLR Assembly and added it, when I run the T-SQL command:

CREATE AGGREGATE Concat (@input nvarchar(max))
RETURNS nvarchar(max)
EXTERNAL NAME Sql_ClrAggregates.Concatenate;

I get the error:

Msg 6558, Level 16, State 1, Line 1
CREATE AGGREGATE failed because type 'Concatenate' does not conform to UDAGG specification due to method 'Accumulate'.

What is the UDAGG specification?


Solution

  • The UDAGG specification partly referrs to the bit supplied between CREATE AGGREGATE and EXTERNAL NAME i.e.

    Concat (@input nvarchar(max)) RETURNS nvarchar(max)
    

    Check that this matches the method in the assembly, in c# this would be

    public void Accumulate(SqlString Value)
    { ... }
    

    with the terminate function returning the result:

    public SqlString Terminate()
    { ... }
    

    You'll get a similar error if you add public fields, methods etc. that don't meet the requirements but that field will be mentioned specifically.