C#和SQL Server 2008 CLR序列化问题 [英] C# and SQL Server 2008 CLR Serialization Problem

查看:84
本文介绍了C#和SQL Server 2008 CLR序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C#中创建一个 SqlUserDefinedAggregate 以附加到我的SQL Server 2008实例。我正在使用.NET 3.5。基本上,我想计算我看到字符串值的次数。由于使用的原因,它确实必须是一个聚合函数。该函数的代码在逻辑上是合理的,但是当我进行部署时,我得到了:

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:


部署错误SQL01268:.Net SqlClient数据提供者:消息6222,级别
16,状态1,行1将类型 GEMCLR.CountTypes标记为本机
序列化,但类型为 GEMCLR.CountTypes的字段 m_types不是
对本机序列化有效。

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 Dictionary< string,int> 。我的代码的轮廓如下所示:

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 () { ... }
}


推荐答案

通常词典不是开箱即用的可序列化的,这是您的问题,有关如何解决此问题的文章很多,例如Adam Semel的如何在其中序列化字典或哈希表C#

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

这篇关于C#和SQL Server 2008 CLR序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆