Why MarshalByRefObject.GetLifetimeService method is final virtual

54 views Asked by At

Accidentally I found out that MarshalByRefObject.GetLifetimeService method on .NET Framework is final virtual.

> typeof(MarshalByRefObject).GetMethod("GetLifetimeService").Attributes
PrivateScope, Public, Final, Virtual, HideBySig, VtableLayoutMask

I saw source code of this class and method looks like normal instance non virtual method:

[System.Security.SecurityCritical]  // auto-generated_required
public Object GetLifetimeService()
{
    return LifetimeServices.GetLease(this); 
}

But than I saw it IL disassembler code:

.method public final hidebysig newslot virtual 
    instance object GetLifetimeService () cil managed 
{
    // method body
}

It is virtual but final (sealed in C#) method that doesn't make sense in my opinion.

Than I checked that strange thing on .NET [Core] and method is not virtual here:

> typeof(MarshalByRefObject).GetMethod("GetLifetimeService").Attributes
PrivateScope, Public, HideBySig

Now I am very interested and want to find out why this happened and how it is possible.

0

There are 0 answers