Description
Follow up to #39838. JSRuntime's API (excluding the unmarshalled ones) use JSON serialization to serialize the args array and as such are subject to being trimmed away. S.T.Js API for its serialization are annotated with RequiresUnreferencedCode with a recommendation to use the source-generator based overload to avoid this.
Blazor's APIs suppress STJ's warnings (since it happens deep in its bowels) and don't have a trimmer safe alternative. Perhaps one option is to annotate all of the JSRuntime APIs with RequiresUnferencedCode
and add an JSRuntime.InvokeAsync overload that accepts exactly one argument a JsonTypeInfo
to go with it. Something like so:
TValue IJSRuntime.InvokeAsync<TArg, TValue>(string method, TArg arg, JsonTypeInfo<TArg> t1, JsonTypeInfo<TValue> t2, CancellationToken cancellationToken)
At the very least, we could require that all code in the framework uses this API for it's interop.