-1

I'm developing a UWP library which has public properties and method parameters of StreamSocket class. However, I'm getting "StreamSocket is not CLS-compliant" warning. What's so special there that Microsoft decided to leave the respective assembly non-CLS-compliant and are there any potential issues I should know about when using/distributing this library? Maybe CLS incompliance will somehow limit the ways my library can be used by other developers?

Alex
  • 2,469
  • 3
  • 28
  • 61

1 Answers1

2

Well, from the documentation:

If you design a CLS–compliant class library, your library will have a guarantee of interoperability with a wide range of programming languages; therefore, your library is likely to have a wider customer base than a version that is not CLS-compliant.

So the [obvious] answer is that they did not have "programming language interoperatibility" in mind when they coded that thing.

I am not surprised to be honest, MS is not exactly known for strictness (IE anyone?)

Read more here: https://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx

UPDATE:

I will try to demystify this a little bit based on the comments.

The CLS (Common Language Specification) defines the features that any language that targets the .NET Framework MUST support. Hence, you should only care about it if your libraries are going to be consumed by a .NET language.

For instance, there is a restriction in the CLS that says that class and member names cannot differ only by case. You can't have one property named MySocket and another one named mySocket. This is important for languages like VB .NET which are not case sensitive.

In the case at hand, your library is exposing StreamSocket, which is not marked as CLS Compliant. What if this class has methods like the samples above and you try to use your library in some VB.NET project? This is what the compiler is warning you about.

JuanR
  • 7,405
  • 1
  • 19
  • 30
  • Uhm... but how does CLS-compliance relate to UWP? It's not like the Common Type System is at the core of the UWP. It's merely one of many projections. – IInspectable Dec 20 '16 at 17:21
  • @IInspectable So in UWP world it's perfectly normal to have CLS-incompliant code in public API of my library (assuming MS does the same and nobody cares)? – Alex Dec 20 '16 at 17:23
  • 1
    @Alex: I don't know. I just don't understand, why compliance with an unrelated type system is required or desirable. You can project **any** non-CLS-compliant type into any .NET projection, so that leaves me puzzled. – IInspectable Dec 20 '16 at 17:25
  • Well, I just needed to make sure I don't do anything stupid when using StreamSocket in public methods of my UWP library (which is a port from .NET Framework's version of my library). In .NET world, CLS-compliance was important but I couldn't find is it so for UWP or not. Now I got your statement that CLS-compliance is not relevant to UWP and I should not care any further. I believe this clears all my concerns, thanks. – Alex Dec 20 '16 at 17:35
  • I don't understand, how this helps. The update talks about the .NET framework. The question is asking about the UWP. Those are distinct platforms, and the Common Language Specification is not part of the latter. – IInspectable Dec 20 '16 at 19:30
  • @IInspectable - CLS compliance, however, is only relevant when speaking about .NET, and has nothing to do with the platform you are targeting. For what it's worth, the OP could target Xamarin.iOS and the CLS compliance requirements wouldn't change. – Sunius Dec 20 '16 at 20:15
  • @Sunius: That is my understanding as well. But neither this proposed answer nor the other - now deleted - answer addressed this. The OP is implementing a UWP library, and the first step towards a solution would be to analyze, why the compiler issues a (meaningless, in context) CLS-compliance warning. – IInspectable Dec 21 '16 at 13:09
  • What's not to understand @IInspectable? The compiler is warning because he is creating a library that is non-CLS compliant. The purpose may be to use it with UWP but he is creating it with C# and exposing a class from a UWP library that is not CLS compliant. The compiler is essentially saying "if someone uses this library with another .NET language, it may blow up". The compiler doesn't know your purpose. It simply warns based on what it knows. – JuanR Dec 21 '16 at 14:54
  • @Juan: CLS compliance is an attribute, that's meaningful when targeting the .NET framework only. When targeting the UWP, there is no such concept. Types are identified and activated by GUID, and class members are identified by index. How this is projected into any given programming language is decided at the language projection's discretion. CLS compliance is certainly not meaningful, and the compiler complaining about it in a UWP library is likely due to a misconfigured proejct, or an erroneous `CLSCompliant` attribute. – IInspectable Dec 21 '16 at 17:39