Calling protected static base member from static do raises MethodAccessException
If the static do block of a class attempts to call a protected static member of a base class, a MethodAccessException is raised because the code from the do block is moved outside the derived class by the compiler
#nowarn "44" // using Uri.EscapeString just because it's protected static
type C(str : string) =
inherit System.Uri(str)
static do
System.Uri.EscapeString("data") |> ignore
C("hello") |> ignore
Expected behavior
The method call should succeed, since the static do is the equivalent to C#'s static constructor, or a warning should be produced that while this will compile it won't work.
Actual behavior
A MethodAccessException is raised on the call
Known workarounds
Move the method call into a static member of the derived class, and call it from the static do block:
static do
C.Do()
static member internal Do() =
System.Uri.EscapeString("data") |> ignore
I should add the real-world case - calling Visual.AffectsRender in an Avalonia custom control class derived from Border.
Hmmm yes this should be allowed. Thanks
Note: This is fixed by enabling --realsig+. Might be worth adding a tests for this specific scenario.