3

I am trying to create a SqlUserDefinedAggregate in C# to attach to my SQL Server 2008 instance. I am working with .NET 3.5. Basically, I want to count the number of times I see string values. It does need to be an aggregate function because of the use. The code for the function is logically sound, but when I go to deploy, I get this:

Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6222, Level 16, State 1, Line 1 Type "GEMCLR.CountTypes" is marked for native serialization, but field "m_types" of type "GEMCLR.CountTypes" is not valid for native serialization.

m_types is a Dictionary<string, int>. The outline of my code looks like this:

[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate (Format.Native)]
public struct CountTypes
{
    private Dictionary<string, int> m_types;

    public void Init ()
    {
        m_types = new Dictionary<string, int> ();
    }

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

    public void Merge (CountTypes group) { ... }

    public SqlString Terminate () { ... }
}
1
  • What did you do to get this working ? Im getting this exact error Commented Apr 29, 2016 at 10:21

1 Answer 1

2

usually a Dictionary is not out of the box serializable and this is your issue, there are plenty of articles on how to solve this issue, for example Adam Semel's How to Serialize a Dictionary or Hashtable in C#.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.