代码之家  ›  专栏  ›  技术社区  ›  Keith Sirmons

如何处理Web引用中符合CLS的问题?

  •  0
  • Keith Sirmons  · 技术社区  · 15 年前

    我正在打开我的C解决方案的程序集中的[assembly:system.clsCompliant(true)]。

    我现在在为SharePointWeb服务生成的代码中收到一些警告。

    以下是不符合CLS的方法之一:

        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetItem", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public uint GetItem(string Url, out FieldInformation[] Fields, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] out byte[] Stream) {
            object[] results = this.Invoke("GetItem", new object[] {
                        Url});
            Fields = ((FieldInformation[])(results[1]));
            Stream = ((byte[])(results[2]));
            return ((uint)(results[0]));
        }
    

    如何删除此警告?

    谢谢您, 基思

    2 回复  |  直到 15 年前
        1
  •  0
  •   John Saunders    15 年前

    我建议您将Web引用放在一个单独的类库项目中,该项目未设置为符合CLS。从主代码中引用该库。

        2
  •  1
  •   Community CDub    8 年前

    您可以使用 [CLSCompliant(false)] 属性以避免出现警告,但这似乎首先会破坏将程序集标记为兼容的对象:假定您希望代码实际上是符合CLS的。

    要使代码符合要求,需要将方法的返回类型从 uint / UInt32 . 公开的无符号类型不符合CLS。

    你可以回来 long / Int64 相反。这个 长的 类型符合CLS,将安全地处理任何可能的 无符号整型 价值。

    如果您不能或不会编辑生成的代码(添加属性或更改返回类型),那么我认为您唯一的选择是将代码移动到单独的、不兼容的程序集。 as John suggests .

    推荐文章