我正在打开[程序集:System.CLSCompliant(true)] 在我的 C# 解决方案的程序集中。

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

以下是不符合 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]));
    }

我怎样才能删除这个警告?

谢谢,基思

有帮助吗?

解决方案

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

其他提示

您可以使用以下标记标记不合规的方法 [CLSCompliant(false)] 属性来避免警告,但这似乎首先破坏了将程序集标记为合规的目标:想必您希望代码实际上符合 CLS。

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

你可以回来 long/Int64 反而。这 long 类型符合 CLS,将安全地处理任何可能的情况 uint 价值。

如果您不能或不会编辑生成的代码(以添加属性或更改返回类型),那么我认为您唯一的选择就是将该代码移动到单独的、不兼容的程序集 正如约翰建议的那样.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top