2011-06-15 81 views
1

我有叫RN中有一个用户自定义类型CLR项目R,RN看起来像的Visual C#CLR项目错误

[Serializable] 
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.UserDefined)] 
public struct RN: INullable, IBinarySerialize 
{ 
    public SqlInt64 Id { get; set; } 
    public SqlGeometry G { get; set; } 
    public SqlInt64? CL { get; set; } 
    public SqlDouble? TT { get; set; } 

    public bool HP { get { return !Object.ReferenceEquals(this.CL, null); } } 

    public RN ToClass(DataRow node); 

    public RN TN(DataRow node); 
    public void P(SqlCommand command); 

    public IEnumerable<RN> N; 

    public override bool Equals(object obj); 
    public bool Equals(RN other); 
    public static bool operator ==(RN rn1, RN rn2); 
    public static bool operator !=(RN rn1, RN rn2); 
    public override int GetHashCode(); 

    public override string ToString(); 

    public bool IsNull; 

    public static RN Null; 

    public static RN FromId(SqlInt64 id); 

    private bool m_Null; 

    public void Write(System.IO.BinaryWriter w) 
    { 
     w.Write(this.IsNull); 
     if (!this.IsNull) 
     { 
      w.Write(this.Id.Value); 
      w.Write(this.G.STAsText().Value); 
      bool CLNull = this.CL.HasValue; 
      w.Write(CLNull); 
      if (!CLNull) 
       w.Write(this.CL.GetValueOrDefault(SqlInt64.MinValue).Value); 
      bool TTNull = this.TT.HasValue; 
      w.Write(TTNull); 
      if (!TTNull) 
       w.Write(this.TT.GetValueOrDefault(SqlInt64.MinValue).Value); 
     } 
    } 
    public void Read(System.IO.BinaryReader r) 
    { 
     this.m_Null = r.ReadBoolean(); 
     if (!this.IsNull) 
     { 
      this.Id = r.ReadInt64(); 
      this.G = SqlGeometry.Parse(r.ReadString()); 
      bool CLNull = r.ReadBoolean(); 
      if (CLNull) 
       this.CL = null; 
      else 
       this.CL = r.ReadInt64(); 
      bool TTNull = r.ReadBoolean(); 
      if (TTNull) 
       this.TT = null; 
      else 
       this.TT = r.ReadInt64(); 
     } 
    } 
} 

当我尝试将项目部署只是作为一个测试,我得到的消息

部署错误SQL01268:净的SqlClient 数据提供:消息6244,级别16, 状态1,行1对 “R.RN” 的尺寸(0)不在 有效范围。大小必须是-1或 号和8000 之间1

我不知道这意味着什么,任何人想知道为什么我添加了Format.UserDefined实施IBinarySerialise如果类型是Format.Native我得到的错误

部署错误SQL01268:净的SqlClient 数据提供:消息6223,级别16, 状态1,行1种类型 “R.RN” 被标记为 本机序列,但场 “ k__BackingField“ ”R.RN“类型为 “Microsoft.SqlServer.Types.Microsoft.SqlServer.Types.SqlGeometry”, 未标记为 “LayoutKind.Sequential”。原生 序列化要求标记为“LayoutKind.Sequential”的类型为 。

会意识到,如果有人能说明什么这些错误的意思,以及他们如何可以解决

感谢

回答

3

的结构有SqlUseDefinedType属性与Format.UserDefined。在这种情况下,还必须指定MaxByteSize。

参见MSDN docs entry

+0

感谢找不到任何错误 – Manatherin 2011-06-15 11:48:28