开发者

C# and SQL Server 2008 CLR Serialization Problem

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
{
  开发者_Go百科  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 () { ... }
}


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#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜