views:

289

answers:

2

Howdy,

I am turning on [assembly: System.CLSCompliant(true)] inside the assemblies of my C# solution.

I am now getting a few warnings inside the generated code for a SharePoint Web Service.

Here is one of the methods that are not CLS-compliant:

    /// <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]));
    }

How can I remove this warning?

Thank you, Keith

+1  A: 

You can mark the non-compliant methods with the [CLSCompliant(false)] attribute to avoid the warnings, but that seems to defeat the object of marking your assemblies as compliant in the first place: Presumably you want the code to actually be CLS-compliant.

To make the code comply, you need to change the return type of the method from uint/UInt32. Exposed unsigned types aren't CLS-compliant.

You could return long/Int64 instead. The long type is CLS-compliant and will safely handle any possible uint value.

If you can't, or won't, edit the generated code (to either add the attribute or alter the return type) then I think your only option is to move that code to a separate, non-compliant assembly as John suggests.

LukeH
A: 

I'd recommend you place your web references in a separate class library project that is not set to be CLS-compliant. Reference that library from your main code.

John Saunders