Visual C++ compiler does not generate non-CLS compliance warning (309813)



The information in this article applies to:

  • Microsoft .NET Framework Class Libraries 1.0
  • Microsoft .NET Framework Class Libraries 1.1
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

This article was previously published under Q309813

SUMMARY

The Visual C++ .NET or Visual C++ 2005 compiler allows the use of the [assembly:CLSCompliant(true)] attribute, but does not generate an error or a warning when the assembly is exposing a class that is a type that is non-Common Language Specification (CLS) compliant. While the compilation does succeed, this could cause a problem when the assembly is used by another compiler that enforces CLS compliance rules. In this version of the Visual C++ .NET or Visual C++ 2005 compiler if you apply the attribute this causes the appropriate metadata to be emitted. However, Visual C++ .NET or Visual C++ 2005 does not currently enforce the CLS compliance rules.

MORE INFORMATION

A Managed C++ class such as the following would exhibit this behavior. The return type UInt32 on method Test is not CLS compliant. Visual C# .NET or Visual C# 2005 and Visual Basic .NET or Visual Basic 2005 compilers generate a compiler error and warning, respectively, for such non-CLS compliant constructs.
using namespace System;
[assembly: CLSCompliant(true)];
namespace NonCLSCompliant{
public __gc class Class1
  {
	public:
		UInt32 Test(void);//This should give an error or warning as UInt32 is not CLS compliant..
  };
}
				

You should exercise caution when you are using a type that is not CLS compliant and marking the assembly as CLS compliant because this could lead to unexpected results.

Modification Type:MajorLast Reviewed:1/5/2006
Keywords:kbinfo kbNativeAttributes KB309813 kbAudDeveloper