Skip to content

Commit 056b049

Browse files
authored
Replace InvokeNew[Async] with InvokeConstructor[Async] (#35949)
1 parent 1ba120b commit 056b049

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ IJSRuntime JS { get; set; }
462462

463463
Create an instance of a JS object using a constructor function and get the <xref:Microsoft.JSInterop.IJSObjectReference>/<xref:Microsoft.JSInterop.IJSInProcessObjectReference> .NET handle for referencing the instance with the following API:
464464

465-
* `InvokeNewAsync` (asynchronous)
466-
* `InvokeNew` (synchronous)
465+
* `InvokeConstructorAsync` (asynchronous)
466+
* `InvokeConstructor` (synchronous)
467467

468468
Examples in this section demonstrate the API calls with the following `TestClass` with a constructor function (`constructor(text)`):
469469

@@ -479,25 +479,25 @@ window.TestClass = class {
479479
}
480480
```
481481

482-
### Asynchronous `InvokeNewAsync`
482+
### Asynchronous `InvokeConstructorAsync`
483483

484-
Use `InvokeNewAsync(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSRuntime> and <xref:Microsoft.JSInterop.IJSObjectReference> to invoke the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>.
484+
Use `InvokeConstructorAsync(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSRuntime> and <xref:Microsoft.JSInterop.IJSObjectReference> to invoke the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>.
485485

486486
```csharp
487-
var classRef = await JSRuntime.InvokeNewAsync("TestClass", "Blazor!");
487+
var classRef = await JSRuntime.InvokeConstructorAsync("TestClass", "Blazor!");
488488
var text = await classRef.GetValueAsync<string>("text");
489489
var textLength = await classRef.InvokeAsync<int>("getTextLength");
490490
```
491491

492492
An overload is available that takes a <xref:System.Threading.CancellationToken> argument or <xref:System.TimeSpan> timeout argument.
493493

494-
### Synchronous `InvokeNew`
494+
### Synchronous `InvokeConstructor`
495495

496-
Use `InvokeNew(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> to invoke the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
496+
Use `InvokeConstructor(string identifier, object?[]? args)` on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> to invoke the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `TestClass` contains a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
497497

498498
```csharp
499499
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
500-
var classRef = inProcRuntime.InvokeNew("TestClass", "Blazor!");
500+
var classRef = inProcRuntime.InvokeConstructor("TestClass", "Blazor!");
501501
var text = classRef.GetValue<string>("text");
502502
var textLength = classRef.Invoke<int>("getTextLength");
503503
```
@@ -630,7 +630,7 @@ In server-side scenarios, JS interop calls can't be issued after Blazor's Signal
630630
* <xref:Microsoft.JSInterop.IJSRuntime.InvokeAsync%2A?displayProperty=nameWithType>
631631
* <xref:Microsoft.JSInterop.JSRuntimeExtensions.InvokeAsync%2A?displayProperty=nameWithType>
632632
* <xref:Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync%2A?displayProperty=nameWithType>
633-
* `InvokeNewAsync`
633+
* `InvokeConstructorAsync`
634634
* `GetValueAsync`
635635
* `SetValueAsync`
636636
* `Dispose`/`DisposeAsync` calls on any <xref:Microsoft.JSInterop.IJSObjectReference>.

aspnetcore/blazor/javascript-interoperability/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ JavaScript (JS) interop calls can't be issued after Blazor's SignalR circuit is
337337
* <xref:Microsoft.JSInterop.IJSRuntime.InvokeAsync%2A?displayProperty=nameWithType>
338338
* <xref:Microsoft.JSInterop.JSRuntimeExtensions.InvokeAsync%2A?displayProperty=nameWithType>
339339
* <xref:Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync%2A?displayProperty=nameWithType>
340-
* `InvokeNewAsync`
340+
* `InvokeConstructorAsync`
341341
* `GetValueAsync`
342342
* `SetValueAsync`
343343
* `Dispose`/`DisposeAsync` calls on any <xref:Microsoft.JSInterop.IJSObjectReference>.

aspnetcore/release-notes/aspnetcore-10.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: wadepickett
44
description: Learn about the new features in ASP.NET Core in .NET 10.
55
ms.author: wpickett
66
ms.custom: mvc
7-
ms.date: 08/13/2025
7+
ms.date: 08/14/2025
88
uid: aspnetcore-10
99
---
1010
# What's new in ASP.NET Core in .NET 10

aspnetcore/release-notes/aspnetcore-10/includes/blazor.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ Blazor adds support for the following JS interop features:
305305

306306
The following asynchronous methods are available on <xref:Microsoft.JSInterop.IJSRuntime> and <xref:Microsoft.JSInterop.IJSObjectReference> with the same scoping behavior as the existing <xref:Microsoft.JSInterop.IJSRuntime.InvokeAsync%2A?displayProperty=nameWithType> method:
307307

308-
* `InvokeNewAsync(string identifier, object?[]? args)`: Invokes the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>:
308+
* `InvokeConstructorAsync(string identifier, object?[]? args)`: Invokes the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>:
309309

310310
```csharp
311-
var classRef = await JSRuntime.InvokeNewAsync("jsInterop.TestClass", "Blazor!");
311+
var classRef = await JSRuntime.InvokeConstructorAsync("jsInterop.TestClass", "Blazor!");
312312
var text = await classRef.GetValueAsync<string>("text");
313313
var textLength = await classRef.InvokeAsync<int>("getTextLength");
314314
```
@@ -330,11 +330,11 @@ Overloads are available for each of the preceding methods that take a <xref:Syst
330330

331331
The following synchronous methods are available on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> with the same scoping behavior as the existing <xref:Microsoft.JSInterop.IJSInProcessObjectReference.Invoke%2A?displayProperty=nameWithType> method:
332332

333-
* `InvokeNew(string identifier, object?[]? args)`: Invokes the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
333+
* `InvokeConstructor(string identifier, object?[]? args)`: Invokes the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
334334

335335
```csharp
336336
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
337-
var classRef = inProcRuntime.InvokeNew("jsInterop.TestClass", "Blazor!");
337+
var classRef = inProcRuntime.InvokeConstructor("jsInterop.TestClass", "Blazor!");
338338
var text = classRef.GetValue<string>("text");
339339
var textLength = classRef.Invoke<int>("getTextLength");
340340
```

0 commit comments

Comments
 (0)