Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my function not CLS-compliant?

I'm getting the following warning message...

Return type of function 'ConnectionNew' is not CLS-compliant.

...for this function:

Public Function ConnectionNew(ByVal DataBaseName As String) As MySqlConnection
      Dim connection As MySqlConnection = Nothing
      connection = getConnection(DataBaseName())
      Return connection
End Function

What does this message mean, and how can I fix it?

like image 537
Urbycoz Avatar asked Aug 15 '11 12:08

Urbycoz


People also ask

Which is not a CLS compliant language?

A CLS-compliant identifier should not start with an underscore. Show activity on this post. It's the underscore.

What does CLS compliant mean?

Being CLS compliant means that you can write code that can be consumed by any language that can be compiled and run on the CLR. But CLS compliance is not required, giving you the flexibility in cases where CLS compliance would be hard or impossible to do.

What is a CLS code?

Rule description. The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages.


1 Answers

It is because you are returning an object of a type that's not CLS compliant. Nothing you can do about that, you didn't write the type. Just acknowledge that you know that it isn't compliant, it isn't otherwise likely to cause any problems. Unless you use the function in another language that doesn't support all the .NET types. Fix:

<CLSCompliant(False)> _
Public Function ConnectionNew(ByVal DataBaseName As String) As MySqlConnection
   '' etc...
End Function
like image 114
Hans Passant Avatar answered Nov 02 '22 01:11

Hans Passant