Add better assembly resolve for PublishTrimmed build option for AspNet Core #18781
Labels
affected-few
This issue impacts only small number of customers
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
feature-platform
Deprecated: Cross-cutting issues related to ASP.NET Core as a platform
investigate
linker-friendliness
Tracking linker friendliness
severity-minor
This label is used by an internal tool
Is your feature request related to a problem? Please describe.
A major feature of .Net core is now to allow project to be publish trimmed (Aka removing unused assembly) and self-contained.
This does not work fine with AspNet Core, as stated here, use reflexion.
Therefore used type in controllers are mostly stripped out (Like smtpclient). Occur if the type is created directly in controllers or injected via dependencies injection.
Describe the solution you'd like
Improve PublishTrimmed option for not remove directly used assembly by controllers.
Additional context
Attached sample project with a simple route /test
TrimProblemExample.zip
This work fine when lauched with visual studio.
This not work with bellow error when lauched with standalone publish with
dotnet publish WebApplication5.csproj --output out
(note that publish option are in the csproj)
Unhandled exception. System.TypeLoadException: Could not load type 'System.Net.Mail.SmtpClient' from assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The text was updated successfully, but these errors were encountered: