This project is read-only.
2
Vote

Problem with overridden methods in sealed classes

description

Overridden methods in sealed classes do not show up in the class documentation for a public build. The reflection.org file contains a reference to the base class method and not the derived class's method. If you use /internal+ or remove the "sealed" keyword, then it does show up correctly. Example class:
 
using System;
 
namespace SealedOverrideBug
{
/// <summary>
/// A base class
/// </summary>
public class BaseTest
{
    /// <summary>
    /// A protected method.
    /// </summary>
    protected virtual void SomeMethod()
    {
        Console.WriteLine("Base: Testing!");
    }
}
 
/// <summary>
/// A sealed derived class.
/// </summary>
public sealed class FailingClass : BaseTest
{
    int x;
 
    /// <summary>
    /// A public constructor
    /// </summary>
    public FailingClass()
    {
        x = 0;
    }
 
    /// <summary>
    /// An override for the virtual method.  This doesn't show up in
    /// the class documentation for a public build.  reflection.org
    /// contains a reference to the base class method and not this one.
    /// If you use /internal+ or remove the "sealed" keyword, then it
    /// does show up correctly.
    /// </summary>
    protected override void SomeMethod()
    {
        Console.WriteLine("Derived: Testing {0}!", x++);
        base.SomeMethod();
    }
 
    /// <summary>
    /// A test
    /// </summary>
    public void CallMethod()
    {
        this.SomeMethod();
    }
}
}
 
Reflection.org:
 
    <element api="M:SealedOverrideBug.FailingClass.#ctor" />
    <element api="M:SealedOverrideBug.FailingClass.CallMethod" />
    *<element api="M:SealedOverrideBug.BaseTest.SomeMethod" />*  <-- Base class method rather than override
    <element api="M:System.Object.ToString">
 
Removing the sealed keyword or using /internal+ results in the correct method showing up:
 
    <element api="M:SealedOverrideBug.FailingClass.#ctor" />
    <element api="M:SealedOverrideBug.FailingClass.SomeMethod" />
    *<element api="M:SealedOverrideBug.FailingClass.CallMethod" />*   <-- Correct method shows up
 
Eric

comments

EWoodruff wrote Jan 18, 2008 at 3:42 AM

Oops. That last bit should be pointint to "SomeMethod" on the line above it.

wrote Jan 30, 2010 at 5:15 AM

EWoodruff wrote Jun 28, 2010 at 4:47 AM

This has been fixed in the June 2010 release. Note that you need to add <protectedSealed expose="true" /> to MRefBuilder.config if you want them included.

wrote Feb 22, 2013 at 1:40 AM