[Regression] .NET 9 ILLinker trims out ControllerContext
setter out of ControllerBase
#59039
Labels
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Description
When using ASP.NET controllers that reference
HttpContext
, the context itself is alwaysnull
when-p:PublishTrimmed=true
is used.Reproduction Steps
The above should give you
500
when trying to execute it in .NET 9-trimmed application.Expected behavior
Controller actions should have access to
HttpContext
, it should not be null.Actual behavior
HttpContext
isnull
, after further digging, the problem is withControllerContext
, I'm not 100% sure but my blind take is that setter gets trimmed out and the property is never initialized when the action is executed as part of incoming request.Regression?
Yes, the property was not trimmed in .NET 8 and earlier (with exactly the same config).
Known Workarounds
Configuration
Other information
Let me know if you're unable to reproduce it, I'll try to come up with repro based on my issue in https://github.com/JustArchiNET/ArchiSteamFarm then. If you're fine reproducing it in my public project, then:
Shortly after launch of the program you can navigate to
localhost:1242/swagger
and try to execute selected endpoints that useHttpContext
, e.g.GET /Api/NLog
, which should normally inform you that you didn't send in websocket request, but in affected build crashes with 500 due to my safeguard here.The commit that fixes the issue for me, which is more like a workaround than actual fix: JustArchiNET/ArchiSteamFarm@8aa0170
I'm not 100% sure if this is an actual issue, since it could also be considered intended behaviour of ILLinker, but I don't believe a regression this big could be intended improvement and expectation from the consumers to add it manually if they need it, hence me reporting it.
The text was updated successfully, but these errors were encountered: