diff --git a/src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntime.cs b/src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntime.cs index e65fb3e9c20f..5a72fe8275d0 100644 --- a/src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntime.cs +++ b/src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntime.cs @@ -23,7 +23,7 @@ protected WebAssemblyJSRuntime() } /// - protected override string InvokeJS(string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId) + protected override string InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId) { var callInfo = new JSCallInfo { @@ -42,7 +42,7 @@ protected override string InvokeJS(string identifier, string? argsJson, JSCallRe } /// - protected override void BeginInvokeJS(long asyncHandle, string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId) + protected override void BeginInvokeJS(long asyncHandle, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId) { var callInfo = new JSCallInfo { diff --git a/src/JSInterop/Microsoft.JSInterop/src/Infrastructure/DotNetDispatcher.cs b/src/JSInterop/Microsoft.JSInterop/src/Infrastructure/DotNetDispatcher.cs index 38e84716e17e..5640fce75a5f 100644 --- a/src/JSInterop/Microsoft.JSInterop/src/Infrastructure/DotNetDispatcher.cs +++ b/src/JSInterop/Microsoft.JSInterop/src/Infrastructure/DotNetDispatcher.cs @@ -42,7 +42,7 @@ public static class DotNetDispatcher /// A JSON representation of the parameters. /// A JSON representation of the return value, or null. [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect application code is configured to ensure return types of JSInvokable methods are retained.")] - public static string? Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo invocationInfo, string argsJson) + public static string? Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo invocationInfo, [StringSyntax(StringSyntaxAttribute.Json)] string argsJson) { // This method doesn't need [JSInvokable] because the platform is responsible for having // some way to dispatch calls here. The logic inside here is the thing that checks whether @@ -72,7 +72,7 @@ public static class DotNetDispatcher /// A JSON representation of the parameters. /// A JSON representation of the return value, or null. [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect application code is configured to ensure return types of JSInvokable methods are retained.")] - public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, string argsJson) + public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, [StringSyntax(StringSyntaxAttribute.Json)] string argsJson) { // This method doesn't need [JSInvokable] because the platform is responsible for having // some way to dispatch calls here. The logic inside here is the thing that checks whether diff --git a/src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs b/src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs index d9810b89cd5c..4092349c3882 100644 --- a/src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs +++ b/src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs @@ -51,7 +51,7 @@ public abstract class JSInProcessRuntime : JSRuntime, IJSInProcessRuntime /// The identifier for the function to invoke. /// A JSON representation of the arguments. /// A JSON representation of the result. - protected virtual string? InvokeJS(string identifier, string? argsJson) + protected virtual string? InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson) => InvokeJS(identifier, argsJson, JSCallResultType.Default, 0); /// @@ -62,5 +62,5 @@ public abstract class JSInProcessRuntime : JSRuntime, IJSInProcessRuntime /// The type of result expected from the invocation. /// The instance ID of the target JS object. /// A JSON representation of the result. - protected abstract string? InvokeJS(string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId); + protected abstract string? InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId); } diff --git a/src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs b/src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs index 59cc9153d72a..d406ed1e6f15 100644 --- a/src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs +++ b/src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs @@ -154,7 +154,7 @@ private void CleanupTasksAndRegistrations(long taskId) /// The identifier for the function invocation, or zero if no async callback is required. /// The identifier for the function to invoke. /// A JSON representation of the arguments. - protected virtual void BeginInvokeJS(long taskId, string identifier, string? argsJson) + protected virtual void BeginInvokeJS(long taskId, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson) => BeginInvokeJS(taskId, identifier, argsJson, JSCallResultType.Default, 0); /// @@ -165,7 +165,7 @@ protected virtual void BeginInvokeJS(long taskId, string identifier, string? arg /// A JSON representation of the arguments. /// The type of result expected from the invocation. /// The instance ID of the target JS object. - protected abstract void BeginInvokeJS(long taskId, string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId); + protected abstract void BeginInvokeJS(long taskId, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId); /// /// Completes an async JS interop call from JavaScript to .NET