[Mono-bugs] [Bug 334505] New: gmcs: InternalsVisibleToAttribute does not affect overriding

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Oct 17 06:26:35 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=334505

           Summary: gmcs:  InternalsVisibleToAttribute does not affect
                    overriding
           Product: Mono: Compilers
           Version: 1.2
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: rharinath at novell.com
        ReportedBy: andyhume32 at yahoo.co.uk
         QAContact: mono-bugs at ximian.com
          Found By: ---


The InternalsVisibleTo attribute can be used in one assembly to inform it that
another should be treated as a "friend".  Thus internal members can be accessed
etc.

gmcs however does not respect this for overriding (it does respected it for
calling).  Where overriding a "protected internal" method it reports CS0507
"cannot change access modifiers when overriding `internal' inherited member",
and for an "internal" method it reports CS0115 "no suitable method found to
override".  Repro below.


gmcs_VirtIntProt_Library1.cs:
[[
[assembly:
System.Runtime.CompilerServices.InternalsVisibleToAttribute("gmcs_VirtIntProt_Library2")]

public class Library1
{
    internal protected virtual int TheProtectedInternalMethod(int type, byte
code)
    {
        return 0x1;
    }

    internal virtual int TheInternalMethod(int type, byte code)
    {
        return 0x1;
    }

    static internal int InternalStaticMethod()
    {
        return 0x1;
    }

    static public int PublicStaticMethod()
    {
        return 0x1;
    }

}
]]

gmcs_VirtIntProt_Library2.cs:
[[
public class Library2 : Library1
{
    internal protected override int TheProtectedInternalMethod(int type, byte
code)
    {
        return 0x10;
    }

    internal override int TheInternalMethod(int type, byte code)
    {
        return 0x10;
    }

    int Foo()
    {
        int i = PublicStaticMethod();
        int j = InternalStaticMethod();
        int k = TheProtectedInternalMethod(1, 2);
        int m = TheInternalMethod(1, 2);
        return 9;
    }
}
]]
(Note also that the filename used in the attribute must match the assembly
name).

When compiled with csc, this is correct code.  Use commands:
[[
csc /debug+ /t:library gmcs_VirtIntProt_Library1.cs
dcsc /debug+ /t:library /r:gmcs_VirtIntProt_Library1.dll
/out:gmcs_VirtIntProt_Library2.dll  gmcs_VirtIntProt_Library2.cs
]]
Note: the /out option is important, see
http://msdn2.microsoft.com/en-us/library/0tke9fxk(VS.80).aspx "This is required
because the compiler has not yet generated the name for the assembly it is
building at the time it is binding to external references."


However gmcs fails with same commands.
[[
gmcs /t:library gmcs_VirtIntProt_Library1.cs
gmcs /t:library /r:gmcs_VirtIntProt_Library1.dll
/out:gmcs_VirtIntProt_Library2.dll  gmcs_VirtIntProt_Library2.cs
]]
producing
[[
gmcs_VirtIntProt_Library2.cs(3,37): error CS0507:
`Library2.TheProtectedInternalMethod(int, byte)': cannot change access
modifiers when overriding `internal' inherited member
`Library1.TheProtectedInternalMethod(int, byte)'
d:\Documents and Settings\alan\My
Documents\Temp\2007-10\gmcs_VirtIntProt_Library1.dll (Location of the symbol
related to previous error)
gmcs_VirtIntProt_Library2.cs(8,27): error CS0115:
`Library2.TheInternalMethod(int, byte)' is marked as an override but no
suitable method found to override
]]

When fixed it should be checked that a strong-named assemblies can be used too.


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


More information about the mono-bugs mailing list