Bug discovered in .NET compiler - mixed-language solutions

  • Thread starter Thread starter Saul Behr
  • Start date Start date
S

Saul Behr

How to reproduce:

1) Define an enumerator MyEnum in a VB project (VB_Proj_1).
2) Create a C# project C_Proj_2, with a reference to VB_Proj_1
3) Define an interface MyInterface in C_Proj_2, which has a method
referencing MyEnum:

void MyMethod(MyEnum x);

4) Create a new VB project VB_Proj_3, with references to both
VB_Proj_1 and C_Proj_2.
5) Create a class in VB_Proj_3 that implements MyInterface. Then,
using the VB smart editor, select the "MyInterface" interface on the
left drop-down, and "MyMethod" from the right drop-down, giving you
the automatically generated method header:

Public Sub MyMethod(ByVal x as MyEnum) Implements MyInterface.MyMethod

That should work, right? Sorry, no can do. You can move heaven and
earth, but you will not get the .NET compiler to accept any method
implementing MyInterface.MyMethod. It simply does not recognize the
MyEnum enumerator as being the same as that defined in the interface,
and you get the error message, "'MyMethod' cannot implement 'MyMethod'
because there is no matching sub on interface 'MyInterface'.

6) If, however, you shift the definition of MyEnum to another, new, C#
project, everything suddenly works fine & dandy.

For all Microsoft's marketing drivel that the .NET languages are all
mutually compatible, they are clearly not. REAL compatibility would
mean you wouldn't even have to have such a thing as a VB project
separate from a C# project; you should simply be able to put them all
together in one happy project. Maybe that's for the Longhorn
release...?
 
You see more of that in Whidbey, esp. in web apps. It is getting better.

As for your bug, it is an IDE issue and not a compatibility of languages
issue.

1. Compile VB_Proj_1.
2. Remove VB_Proj_1 from solution
3. Make a reference in C_Proj_2 to VB_Proj_1 compiled DLL
4. Compile C_Proj_2
5. Remove C_Proj_2 from solution
6. Create References in VB_Proj_3 to both DLLs
7. Compiles without any issue

In a normal team situation, you would not have project references like this,
so it is not a major issue in the normal situation. When you are designing
software, in one solution, you normally use one language. This also stops
the issue.

Once compiled, there is no issue. As I mentioned before, this is getting
better in the 2.0 Framework.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
Back
Top