PRB: The Common Language Runtime Does Not Support Type 'internal virtual' Methods (317129)



The information in this article applies to:

  • Microsoft .NET Framework 1.0
  • Microsoft Visual C# .NET (2002)

This article was previously published under Q317129

SYMPTOMS

If you create a public class with a method that is declared as type internal virtual, you may be able to override the method from another assembly. You should not be able to do this with a method that is declared internal.

CAUSE

The Common Language Runtime (CLR) does not currently support this functionality. The bits that are used to annotate an internal virtual method are identical to the bits that are used to annotate a public virtual method, so the CLR cannot differentiate between the two.

RESOLUTION

To resolve this problem, you can declare a method as internal virtual, but you should remember that it may be possible to override the method from another assembly. This is a potential security risk in that other languages may be able to access this method marked as non-public as if it were actually declared as public. The Microsoft Visual C# compiler generates a CS0679 warning message for these methods.

STATUS

This behavior is by design.

MORE INFORMATION

To see the CS0679 warning message, compile the following Visual C# class in Microsoft Visual Studio .NET or with the Visual C# compiler (Csc.exe):
     public class Class1
     {
          internal virtual void IVMethod() 
          {
          }
     }
				
After you compile the code, you receive the following warning message:
c:\class1.cs(3,25): warning CS0679: Other languages may permit the internal virtual member 'Class1.IVMethod()' to be overridden

Modification Type:MinorLast Reviewed:1/23/2004
Keywords:kbCompiler kbLangC kbnofix kbprb kbSecurity KB317129