Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLS Compliance warning CS3016 is reported on non-public members #4293

Closed
dsplaisted opened this issue Aug 2, 2015 · 6 comments
Closed

CLS Compliance warning CS3016 is reported on non-public members #4293

dsplaisted opened this issue Aug 2, 2015 · 6 comments
Labels
Area-Compilers Need More Info The issue needs more information to proceed.

Comments

@dsplaisted
Copy link
Member

Compile the following code:

using System;

[assembly:CLSCompliant(true)]

[CLSCompliant(false)]
public sealed class SharingBoundaryAttribute : Attribute
{
    public SharingBoundaryAttribute(params string[] sharingBoundaryNames)
    {
    }
}

class LightweightWebBenchmark
{
    [SharingBoundary("name")]
    public object WebScopeFactory { get; set; }
}

EXPECTED: No warnings
ACTUAL: warning CS3016: Arrays as attribute arguments is not CLS-compliant

If you try to disable the warning by putting [CLSCompliant(false)] on the LightweightWebBenchmark class (or its WebScopeFactory property), you get this error:

warning CS3019: CLS compliance checking will not be performed on 'LightweightWebBenchmark' because it is not visible from outside this assembly

So for code like this it doesn't appear possible to avoid CLS compliance warnings, without disabling CLS compliance for the whole assembly or using specifically ignoring this warning.

dsplaisted added a commit to dsplaisted/corefx that referenced this issue Aug 2, 2015
dotnet/roslyn#4293 CLS Compliance warning CS3016 is reported on non-public members
@jaredpar jaredpar added this to the 1.1 milestone Aug 4, 2015
@AlekseyTs
Copy link
Contributor

The behavior is consistent with behavior of VS2013 compiler. Moving to 2.0. I am not sure if it is worth changing the behavior at all.

@AlekseyTs AlekseyTs modified the milestones: 2.0, 1.1 Aug 4, 2015
@AlekseyTs AlekseyTs removed their assignment Aug 4, 2015
dsplaisted added a commit to dsplaisted/corefx that referenced this issue Aug 8, 2015
dotnet/roslyn#4293 CLS Compliance warning CS3016 is reported on non-public members
dsplaisted added a commit to dsplaisted/corefx that referenced this issue Aug 21, 2015
* Use ReaderWriterLockSlim
* Move duplicated code into common folder
* Use EmptyArray<T> instead of new T[0]
* Fix CLS Compliance error in System.Composition test library
  (See dotnet/roslyn#4293: CLS Compliance warning CS3016 is reported on
  non-public members)
* Rename SilverlightTraceWriter.cs to DebuggerTraceWriter.cs
* Use CommonPath build property to include common files
* Remove unnecessary AssemblyInfo.cs files
* Remove unused private constant in System.Composition.AttributedModel
rajansingh10 pushed a commit to rajansingh10/corefx that referenced this issue Oct 16, 2015
* Use ReaderWriterLockSlim
* Move duplicated code into common folder
* Use EmptyArray<T> instead of new T[0]
* Fix CLS Compliance error in System.Composition test library
  (See dotnet/roslyn#4293: CLS Compliance warning CS3016 is reported on
  non-public members)
* Rename SilverlightTraceWriter.cs to DebuggerTraceWriter.cs
* Use CommonPath build property to include common files
* Remove unnecessary AssemblyInfo.cs files
* Remove unused private constant in System.Composition.AttributedModel
rajansingh10 pushed a commit to rajansingh10/corefx that referenced this issue Oct 18, 2015
* Use ReaderWriterLockSlim
* Move duplicated code into common folder
* Use EmptyArray<T> instead of new T[0]
* Fix CLS Compliance error in System.Composition test library
  (See dotnet/roslyn#4293: CLS Compliance warning CS3016 is reported on
  non-public members)
* Rename SilverlightTraceWriter.cs to DebuggerTraceWriter.cs
* Use CommonPath build property to include common files
* Remove unnecessary AssemblyInfo.cs files
* Remove unused private constant in System.Composition.AttributedModel
@jaredpar jaredpar added the Bug label Dec 7, 2015
@jaredpar
Copy link
Member

jaredpar commented Dec 7, 2015

So for code like this it doesn't appear possible to avoid CLS compliance warnings, without disabling CLS compliance for the whole assembly or using specifically ignoring this warning.

Have you tried #pragma warning disable?

@jaredpar
Copy link
Member

jaredpar commented Dec 7, 2015

@AlekseyTs if it's consistent with native compiler I agree at least 2.0. However is this a bug or "by design"? If it's a bug I'd like to keep for fixing, if not though I'd like to close it out.

@jaredpar jaredpar added Need More Info The issue needs more information to proceed. and removed Bug labels Dec 7, 2015
@AlekseyTs
Copy link
Contributor

@jaredpar As far as I know, there is no compiler spec for CLS Compliance that we can refer to. For Roslyn, our goal regarding CLS Compliance was to duplicate native compiler behavior. So, it is everyone's judgement call whether this is by design or a bug. Regardless, in my personal opinion, it is not worth changing the behavior in this area.

CC @amcasey

@amcasey
Copy link
Member

amcasey commented Dec 7, 2015

As @AlekseyTs said, when we implemented this, we found ourselves in a tight spot - the rules aren't strict enough to ensure that APIs will work across language enough, but strengthening them would have broken existing programs. While I hope that eventually we will be able to implement stronger rules as analyzers, our present goal is to mimic dev12 on a best-effort basis, favoring fewer, rather than more, diagnostics.

@amcasey amcasey closed this as completed Dec 7, 2015
@jaredpar
Copy link
Member

jaredpar commented Dec 7, 2015

Given the constraints here I agree with Close / Won't fix. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Need More Info The issue needs more information to proceed.
Projects
None yet
Development

No branches or pull requests

5 participants