This post originated from an RSS feed registered with .NET Buzz
by Frans Bouma.
Original Post: CLS Compliance testing is useless
Feed Title: Frans Bouma's blog
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/fbouma/Rss.aspx
Feed Description: Generator.CreateCoolTool();
After reading Patrick Steele's blog about the failure of CLS Compliance testing in VB.NET, I thought he was wrong, because he uses UInt32 as type, which is a native system type (i.e. a .NET type: System.UInt32).
However, he was right. The C# compiler fails to compile a simple statement like (when CLS Compliance testing is turned on via an attribute):
public System.UInt32 Test;
Correct behaviour of the C# compiler? No. The reason why the C# compiler makes a mistake here is that I use a .NET type, System.UInt32, which is available to any .NET language (it's in the .NET System namespace after all). Therefor, if I specify a public identifier with this type, no matter what language is consuming the type, it can use it. Proof of this is VB.NET, which lacks an unsigned integer type, but can perfectly work with System.UInt32. Also, why would System.UInt32 fail CLS Compliance, but would another value type like System.Data.SqlTypes.SqlString not fail CLS Compliance testing (although it exposes implicit operators not usable in VB.NET!) ?
So is CLS Compliance testing of any use? Not that I'm aware of. If native .NET types, located in the System namespace, can't be used as types for public identifiers (like parameters, properties, return values etc.), why are these types defined in the first place? Because apparently some languages can't use them, otherwise these native, .NET types wouldn't cause a CLS Compliance violation!
Microsoft: or come up with valid rules, founded on solid reasoning, for CLS Compliance testing or stop with the CLS Compliance testing altogether, since at the moment it cries fool when compiling perfect usable code.
The conclusion of Patrick's article shouldn't be: why doesn't the VB.NET compiler test correctly, but why does the C# compiler test incorrectly.