[Mono-bugs] [Bug 542487] New: Public extension method ignored with a non-public member of the same name

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Sep 27 12:00:31 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=542487


           Summary: Public extension method ignored with a non-public
                    member of the same name
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.4.x
          Platform: i686
        OS/Version: Windows
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: naasking at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


The following code fails to compile:

public static class MessageFails
{
    public static MailMessage ParseMailMessage(this string raw)
    {
        var email = new MailMessage();

    // error CS0122: `System.Net.Mail.MailMessage.ContentTransferEncoding' 
        // is inaccessible due to its protection level
        var transferEncoding = email.ContentTransferEncoding();
        return email;
    }

    public static TransferEncoding ContentTransferEncoding(this MailMessage
email)
    {
        throw new NotSupportedException();
    }
}

Reproducible: Always

Actual Results:  
error CS0122

Expected Results:  
Compilation succeeds. Compilation on MS.NET succeeds. This may just be a
difference between .NET's class libraries and Mono's class libraries; perhaps 
the MS.NET libraries don't have a non-public ContentTransferEncoding member.

However, resolving this case as a CS0122 error seems like a portability
problem. It's simply not sensible for the compiler to prefer a non-public
overload over a public extension method, in a context where non-public members
are inaccessible. Clearly the public extension method is a valid selection in
this case.

It's a portability problem because developers must now ensure their extension
method names do not conflict with any non-public member names in all available
class libraries. This is a significant and unnecessary burden.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list