-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET 9 trimmed application fails with System.TypeLoadException (Method trimmed but interface still listed on type). #109850
Comments
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection |
Also @dotnet/illink |
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas |
@jlaanstra I wasn't able to repro this using the code you shared. Did you publish with |
@sbomer Yes to using PublishTrimmed.
Attached is a repro project. Select the Debug,AnyCPU config, then publish from VS, then run the published exe. |
In the repro, we mark ServiceProvider's impl of IKeyedServiceProvider, but then never reach Swapping the order of runtime/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Lines 418 to 419 in 35e23f7
#110098 fixes the immediate issue, but I'm concerned there might be more subtle dependencies on the ordering of these two steps, so this will need more investigation. There's also still the open question of why this fails when publishing from VS, but not when publishing from the command-line. |
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: