-
Notifications
You must be signed in to change notification settings - Fork 127
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
Do not trimm methods marked with JSInvokable #3209
Comments
@pavelsavara - who might know what the intention here is. |
The overall problem is that such code, when only used by JS is not statically visible as being used by linker. For This is similar but not same as problem with |
Just curious - can |
Probably yes, but I don't know all use cases nor done gap analysis. @danroth27 is there desire for this ? |
Hmm...I'm not sure. We don't know statically if these methods are being used or not. What's the linker philosophy on situations like this? Do we err on the side of aggressively trimming things and requiring the user to tell us if we shouldn't? Or do we err on making things work at the expensive of not trimming stuff that may not be used? If someone is writing a library that uses these attributes would our guidance be that they always need to be marked so they don't get trimmed? If that's our guidance, then it would be nice if the attributes themselves could signal that to the trimmer without additional metadata getting manually added by the user. |
That's interesting point about libraries. |
Interesting that here https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly/src/Services/DefaultWebAssemblyJSRuntime.cs the |
FYI: the ongoing PR documentation change dotnet/AspNetCore.Docs#28631 |
@MackinnonBuck we could cleanup |
From a trimmer perspective it's "trim as much as possible", but that's just the tool. I think the right question is what is the SDK's take and more specifically what is our designed goal for a given vertical. For example in console apps we're more strict and there we would require the code to declare these dependencies such that trimmer can see them (either via On the other hand for Blazor, or Xamarin verticals we tend to "just make things work", which would likely lead to automatically rooting these. That said, the default for Blazor/Xamarin is to NOT trim user code or NuGets, so this should not be a problem there - and if a given library opts into aggressive trimming, it would need to root these somehow explicitely. |
Could depend on TrimMode. full - trim as much as possible, partial - make things work. This would make sense, I only recently found out that WASM doesn't even support full mode (from docs I thought its the default?), the razor components / pages get removed #3160 (comment) |
Makes sense
It's common to use |
Another idea: Maybe it would be possible to add a warning when
Yes. The blazor doc is now updated regarding |
Just to add what other discussions similar to this ended up with: The primary problem with adding functionality like "Always keep all methods with the So in general we will try to figure out if there's some other mechanism which could make it less unconditional. The For future issues/questions, please create them in the dotnet/runtime repo - since the trimmer code base moved there. |
This is just an offer, but while creating this doc issue dotnet/AspNetCore.Docs#28630
I was wondering whatever it would make sense to just not trim those methods by default.
More detailed explanation in the issue above, but
TL;DR: In case of JS Interop (Call .NET from JS) the linker will remove methods with JSInvokable because usually there will be no references to them.
While inspecting aspnetcore source code I found a way how to deal with it.
But due to lack of documentation, many people do not know that their method might be trimmed and how to solve it. My offer is either to document it somewhere or make it so that the linker will not touch methods marked with
JSInvokable
.The text was updated successfully, but these errors were encountered: