icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.62k stars 3.36k forks source link

OverridableAttribute missing from the decompiled code when using a winmd file. #3177

Open jlaanstra opened 8 months ago

jlaanstra commented 8 months ago

Input code

In Windows.winmd from a recent Windows SDK (C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.22621.0\Windows.winmd), the Windows.UI.Xaml.UIElement has the following attributes in il:

        .custom instance void [Windows.winmd]Windows.Foundation.Metadata.OverridableAttribute::.ctor() = (
        01 00 00 00
    )
    [Windows.winmd]Windows.UI.Xaml.IUIElementOverrides,
               .custom instance void [Windows.winmd]Windows.Foundation.Metadata.OverridableAttribute::.ctor() = (
        01 00 00 00
    )

Erroneous output

In the C# code this attribute is not listed.

Details

siegfriedpammer commented 8 months ago

Thank you for reporting this. However, these attributes do not belong to the type declaration, but one of its interface implementations, which can be deduced from the .interfaceimpl type ... directive preceding the .custom directive, but is also visible in the 0C CustomAttribute metadata table.

In C# there is no syntax for adding attributes to the base interface list, so they cannot be added to the C# code. We could add them as comments, but I am not sure about that yet.

What I am going to do: