Visual C# CLR 项目错误
我有一个 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();
}
}
}
当我尝试部署该项目作为测试时,我收到消息
部署错误 SQL01268:.Net SqlClient 数据提供者:Msg 6244,级别 16, 状态 1,第 1 行 尺寸 (0) 为 “R.RN”不在 有效范围。大小必须为 -1 或 a 1 到 8000 之间的数字。
我不知道这意味着什么,对于任何想知道为什么我添加 Format.UserDefined 并实现 IBinarySerialise 的人来说,如果类型是 Format.Native 我收到错误
部署错误 SQL01268:.Net SqlClient 数据提供者:Msg 6223,级别 16, 状态 1,线路 1 类型 “R.RN”标记为 本机序列化,但字段 “k__BackingField”类型 “R.RN”类型 “Microsoft.SqlServer.Types.Microsoft.SqlServer.Types.SqlGeometry”, 没有标记为 “布局种类.顺序”。本国的 序列化要求类型为 标有“LayoutKind.Sequential”。
如果有人能解释这些错误的含义以及如何解决它们,我们将不胜
感激
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 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. 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
该结构具有带有
Format.UserDefined
的SqlUseDefinedType
属性。在这种情况下,还必须指定 MaxByteSize。请参阅 MSDN 文档条目。
The struct has the
SqlUseDefinedType
attribute withFormat.UserDefined
. In that case, MaxByteSize must also be specified.See MSDN docs entry.