Don''t be "Not most specific"

While teaching C# the other day, it occurred to me that in C#, you can create differing method signatures by playing with the parameter types as well as modifiers (ref or out). This works in C#, because when you call the method using the argument modifiers (ref or out) it selects the appropriate signature; but what about when you call this from Visual Basic .NET?

namespace Hundhausen
 public class Foo
  public void Bar(ref string s) {}
  public void Bar(string s) {}

When you consume this class from Visual Basic .NET and call it like this:

Dim f As New Hundhausen.Foo
f.Bar(“Hello World”)

It gives this message:

Interesting behavior, isn’t it? The solution is to always compile your C# code with CLSCompliant attribute set to true and then this nonsense won’t occur.

Here’s the project, if you want to play with it.