2011-06-15 80 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