.NET 9 trimmed application fails with System.TypeLoadException (Method trimmed but interface still listed on type). #109850
Labels
area-Tools-ILLink
.NET linker development as well as trimming analyzers
untriaged
New issue has not been triaged by the area owner
Description
After updating to .NET 9 a trimmed application fails in debug configuration with a System.TypeLoadException: Method 'GetKeyedService' in type 'Microsoft.Extensions.DependencyInjection.ServiceProvider' from assembly 'Microsoft.Extensions.DependencyInjection, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
Based on inspecting the trimmed dll, the ServiceProvider has the IKeyedServiceProvider interface listed but none of the methods are present.
Reproduction Steps
Create a new console app and replace Main with:
Publish the exe and run it to make sure the trimmed exe is ran.
Expected behavior
No TypeLoadException should be thrown. A trimmed application should work just like untrimmed since there are no trim warnings.
Actual behavior
Application fails in debug configuration with a System.TypeLoadException: Method 'GetKeyedService' in type 'Microsoft.Extensions.DependencyInjection.ServiceProvider' from assembly 'Microsoft.Extensions.DependencyInjection, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
Regression?
Yes, from .NET 8
Known Workarounds
No response
Configuration
.NET 9 on Windows 11, x64, running as AnyCPU.
Other information
Project file:
The text was updated successfully, but these errors were encountered: