CLS-Compliance and Array Parameter Rank

T

TC

I just upgraded some code to VB 2005. When I did so, Visual Studio
generated several warnings telling me about things which weren't quite
perfect in my code. I resolved all the warnings except one. I need help
with this one.

'Public Function Multiply(A(,) As Double, B() As Double) As Double()'
is not CLS-compliant because it overloads 'Public Function
Multiply(A(,) As Double, B(,) As Double) As Double(,)' which differs
from it only by array of array parameter types or by the rank of the
array parameter types.

Apparently, my code is not CLS-compliant because B() has the same
parameter signature as B(,) under the CLS rules. I understand this
problem, but I don't know how to fix it.

The only solution I see is to stop overloading (i.e. change the name of
one of the two functions), but that will change the public signature of
my code. Can anyone suggest a better solution?


-TC
 
M

Mattias Sjögren

The only solution I see is to stop overloading (i.e. change the name of
one of the two functions), but that will change the public signature of
my code. Can anyone suggest a better solution?

If you don't care about CLS compliance you can apply the
CLSCompliant(False) attribute to the method to get rid of the warning.


Mattias
 
T

TC

Mattias,

Thanks for the advice. Unfortunately, I'm forced to care about CLS
compliance. The module in question is referenced by many projects, some
of which must be CLS compliant.

-TC
 
J

Jay B. Harlow [MVP - Outlook]

TC,
What Mattias was suggesting was:

<Assembly: CLSCompliant(True)>

Public Class Something

<CLSCompliant(False)> _
Public Function Multiply(ByVal A(,) As Double, ByVal B() As Double) As
Double()
Return Nothing
End Function

Public Function Multiply(ByVal A(,) As Double, ByVal B(,) As Double) As
Double(,)
Return Nothing
End Function

End Class

You can have the entire assembly CSL compliant, except selected types &
methods, as above.

NOTE: I don't know why but it makes a difference which one you use
<CLSCompliant(False)> on...

This is similar to System.Convert.ToUInt32() method. The System.Convert
class is CLS Compliant, however the ToUInt32 is not, as UInt32 is not.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Mattias,
|
| Thanks for the advice. Unfortunately, I'm forced to care about CLS
| compliance. The module in question is referenced by many projects, some
| of which must be CLS compliant.
|
| -TC
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top