开发者

Visual C# CLR Project Error

I have a clr project R with a User defined type called RN in it, RN looks like

[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();
        }
    }
}

When i try to deploy the proj开发者_开发百科ect just as a test i get the message

Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6244, Level 16, State 1, Line 1 The size (0) for "R.RN" is not in the valid range. Size must be -1 or a number between 1 and 8000.

I have no idea what this means, for anyone wondering why i have added the Format.UserDefined and implemented IBinarySerialise if the type is Format.Native i get the error

Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6223, Level 16, State 1, Line 1 Type "R.RN" is marked for native serialization, but field "k__BackingField" of type "R.RN" is of type "Microsoft.SqlServer.Types.Microsoft.SqlServer.Types.SqlGeometry", which is not marked with "LayoutKind.Sequential". Native serialization requires the type to be marked with "LayoutKind.Sequential".

It would be appreciated if someone could explain what these errors mean and how they can be resolved

Thanks


The struct has the SqlUseDefinedType attribute with Format.UserDefined. In that case, MaxByteSize must also be specified.

See MSDN docs entry.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜