Incompatibility - C# allows optional+params, VB does not #7096
Replies: 2 comments 5 replies
-
I think CLS compliance only checks the individual features, and optional parameters and params are each separately CLS. Really makes me wonder how C# 1-3 would have handled implementing a VB interface that declared a method with optional parameters. |
Beta Was this translation helpful? Give feedback.
-
You might be able to make this work by manually specifying the relevant attributes that allow
Such definitions should be "correctly" encoded in IL, and therefore consumable "as expected" from languages that support such a combination. But, it may still run into quirks on the VB side of things. |
Beta Was this translation helpful? Give feedback.
-
Consider a class library that has an interface with a method taking an optional parameter and a
params
array:This works fine in C#. But a consuming application might be written in VB.NET, and there's no way to implement this interface.
One would think it would be:
But this gives a compile error:
Removing either
Optional
orParamArray
from the VB definition doesn't work, because it no longer conforms to the interface.How can one prevent such problems? I'm not sure that VB should support this, but I'd at least like to be warned when compiling C# code that some consumers might not be able to implement the interface. I've set
[assembly: CLSCompliant(true)]
on the C# library because I thought that's exactly what is for - but it does not warn or error on this.Is such code CLS compliant?
Should an analyzer have found this?
Also, is this the best place to discuss this issue?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions