简体   繁体   English

Visual C#CLR项目错误

[英]Visual C# CLR Project Error

I have a clr project R with a User defined type called RN in it, RN looks like 我有一个clr项目R,其中有一个名为RN的用户定义类型,RN看起来像

[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 project 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. 部署错误SQL01268:.Net SqlClient数据提供程序:消息6244,级别16,状态1,行1“ R.RN”的大小(0)不在有效范围内。 Size must be -1 or a number between 1 and 8000. 大小必须为-1或1到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 我不知道这意味着什么,对于任何想知道为什么我添加了Format.UserDefined并实现IBinarySerialise的人(如果类型为Format.Native的话),我会收到错误消息

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". 部署错误SQL01268:.Net SqlClient数据提供程序:消息6223,级别16,状态1,行1类型“ R.RN”已标记为本机序列化,但类型为“ R.RN”的字段“ k__BackingField”的类型为“ Microsoft” “ .SqlServer.Types.Microsoft.SqlServer.Types.SqlGeometry”,未标记为“ LayoutKind.Sequential”。 Native serialization requires the type to be marked with "LayoutKind.Sequential". 本机序列化要求将类型标记为“ 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 . 该结构具有SqlUseDefinedType属性和Format.UserDefined In that case, MaxByteSize must also be specified. 在这种情况下,还必须指定MaxByteSize。

See MSDN docs entry . 请参阅MSDN文档条目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM