BUG: C# v7.10.6001.4 Compiler

B

Brian Gideon

I believe I have found a bug in the C# 1.1 compiler. I apologize if
this has already been reported, but I couldn't find anything in
Microsoft's knowledge base.

1. Create a solution with two class library projects: ProjectA and
ProjectB.

2. Add a reference to System.Messaging.dll in ProjectA.

3. Add the following class to ProjectA.

namespace ProjectA
{
public class Foo
{
public Foo() { }

public Foo(long x) { }

// Notice that this is private!
private Foo(System.Messaging.Message m) { }
}
}

4. Add a reference to ProjectA in ProjectB. A reference to
System.Messaging.dll should not be needed in ProjectB since it is not
part of the public interface in ProjectA.

5. Add the following class to ProjectB

namespace ProjectB
{
public class Bar
{
public Bar()
{
// This line is fine.
ProjectA.Foo a = new ProjectA.Foo();

// This line causes an error when uncommented.
ProjectA.Foo b = new ProjectA.Foo(1);
}
}
}

6. Build the solution. You will get the following error when ProjectB
compiles.

error CS0012: The type 'System.Messaging.Message' is defined in an
assembly that is not referenced. You must add a reference to assembly
'System.Messaging'.

7. There's nothing special about System.Messaging.dll. It just happens
to be what I chose for this example. Play around with
commenting/uncommenting code in both classes to verify that this is
indeed unexpected behavior.

Brian
 
N

Nathan Baker

Presumably they are already aware of this issue, since it has been
fixed in the C# compiler version 8.00.50727.42.
 

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