dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.47k stars 4.76k forks source link

Trimmed winforms app crashes #96516

Closed sbomer closed 10 months ago

sbomer commented 11 months ago

PublishTrimmed with a dotnet new winforms app, using the dotnet9 package feed. The app fails with a TypeLoadException:

Virtual static method 'get_VTable' is not implemented on type 'Windows.Win32.Media.Audio.IMessageFilter' from assembly 'System.Windows.Forms.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
InnerException:   <none>
StackTrace (generated):
    SP               IP               Function
    000000ECE5775830 0000000000000000 System_Windows_Forms!System.Windows.Forms.Application+ThreadContext.<get_ComponentManager>g__GetExternalComponentManager|42_0()+0x1
    000000ECE57758E0 00007FFD1D6B36B0 System_Windows_Forms!System.Windows.Forms.Application+ThreadContext.get_ComponentManager()+0x50
    ...

IMessageFilter is a CsWin32-generated struct:

internal unsafe partial struct IMessageFilter :IVTable<IMessageFilter,IMessageFilter.Vtbl>,IComIID { ... }

IVTable<IMessageFilter,IMessageFilter.Vtbl> is what implements IVTable, including the VTable getter:

internal unsafe interface IVTable<TComInterface, TVTable> : IVTable
    where TVTable : unmanaged
    where TComInterface : unmanaged, IVTable<TComInterface, TVTable>
{
    ...
    static System.Com.IUnknown.Vtbl* IVTable.VTable { get; } = (System.Com.IUnknown.Vtbl*)CreateVTable();

    private static TVTable* CreateVTable() { ... }
}

The trimmed output shows that IMessageFilters interface impl of IVTable<IMessageFilter,IMessageFilter.Vtbl> has been removed:

internal struct IMessageFilter : IVTable, IComIID { ... }

cc @LakshanF

ghost commented 11 months ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.

Issue Details
`PublishTrimmed` with a `dotnet new winforms` app, using the dotnet9 package feed. The app fails with a `TypeLoadException`: ``` Virtual static method 'get_VTable' is not implemented on type 'Windows.Win32.Media.Audio.IMessageFilter' from assembly 'System.Windows.Forms.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. InnerException: StackTrace (generated): SP IP Function 000000ECE5775830 0000000000000000 System_Windows_Forms!System.Windows.Forms.Application+ThreadContext.g__GetExternalComponentManager|42_0()+0x1 000000ECE57758E0 00007FFD1D6B36B0 System_Windows_Forms!System.Windows.Forms.Application+ThreadContext.get_ComponentManager()+0x50 ... ``` `IMessageFilter` is a CsWin32-generated struct: ```csharp internal unsafe partial struct IMessageFilter :IVTable,IComIID { ... } ``` `IVTable` is what [implements](https://github.com/microsoft/CsWin32/blob/77c14043ff0cd9e52bb73367bc43a4218e3a7441/src/Microsoft.Windows.CsWin32/templates/IVTable%602.cs#L1) `IVTable`, including the `VTable` getter: ```csharp internal unsafe interface IVTable : IVTable where TVTable : unmanaged where TComInterface : unmanaged, IVTable { ... static System.Com.IUnknown.Vtbl* IVTable.VTable { get; } = (System.Com.IUnknown.Vtbl*)CreateVTable(); private static TVTable* CreateVTable() { ... } } ``` The trimmed output shows that `IMessageFilter`s interface impl of `IVTable` has been removed: ``` internal struct IMessageFilter : IVTable, IComIID { ... } ``` cc @LakshanF
Author: sbomer
Assignees: sbomer
Labels: `untriaged`, `area-Tools-ILLink`, `needs-area-label`
Milestone: -