Soenneker.Blazor.Utils.BlazorOutputInvoker 4.0.1017

Prefix Reserved
dotnet add package Soenneker.Blazor.Utils.BlazorOutputInvoker --version 4.0.1017
                    
NuGet\Install-Package Soenneker.Blazor.Utils.BlazorOutputInvoker -Version 4.0.1017
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Blazor.Utils.BlazorOutputInvoker" Version="4.0.1017" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Utils.BlazorOutputInvoker" Version="4.0.1017" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Utils.BlazorOutputInvoker" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Blazor.Utils.BlazorOutputInvoker --version 4.0.1017
                    
#r "nuget: Soenneker.Blazor.Utils.BlazorOutputInvoker, 4.0.1017"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Blazor.Utils.BlazorOutputInvoker@4.0.1017
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Blazor.Utils.BlazorOutputInvoker&version=4.0.1017
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Utils.BlazorOutputInvoker&version=4.0.1017
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Blazor.Utils.BlazorOutputInvoker

An adapter that exposes a Func<TInput, ValueTask<TOutput>> as an instance [JSInvokable] method and returns the serialized result to JavaScript.

Installation

dotnet add package Soenneker.Blazor.Utils.BlazorOutputInvoker

There is no service registration. Construct the callback, retain a DotNetObjectReference, and pass it to the JavaScript code that owns the call site.

Usage

using Microsoft.JSInterop;
using Soenneker.Blazor.Utils.BlazorOutputInvoker;

var invoker = new BlazorOutputInvoker<NormalizeRequest, NormalizeResult>(request =>
    ValueTask.FromResult(new NormalizeResult(request.Value.Trim(), request.Value.Length)));

DotNetObjectReference<BlazorOutputInvoker<NormalizeRequest, NormalizeResult>> reference =
    DotNetObjectReference.Create(invoker);

await module.InvokeVoidAsync("registerNormalizeCallback", reference);

public sealed record NormalizeRequest(string Value);
public sealed record NormalizeResult(string Value, int OriginalLength);

JavaScript awaits InvokeWithOutput and receives a normal object:

let normalizeCallback;

export function registerNormalizeCallback(reference) {
    normalizeCallback = reference;
}

export function unregisterNormalizeCallback() {
    normalizeCallback = null;
}

export async function normalize(value) {
    if (!normalizeCallback)
        throw new Error("The normalize callback has not been registered.");

    const result = await normalizeCallback.invokeMethodAsync("InvokeWithOutput", { value });
    return result;
}

When the owner is disposed, unregister the browser callback before disposing the object reference:

await module.InvokeVoidAsync("unregisterNormalizeCallback");
reference.Dispose();

Contract and failure behavior

  • TInput and TOutput pass through Blazor's System.Text.Json-based interop serialization. Use serializable DTOs with predictable JSON names; delegates, streams, cyclic graphs, and arbitrary runtime objects are not suitable return values.
  • A nullable output is serialized as JavaScript null. Model expected failures explicitly in the output DTO when JavaScript should handle them as normal results.
  • If the delegate throws, JavaScript's invokeMethodAsync promise rejects. Await it and handle the error; do not expose internal exception details directly to end users.
  • The wrapper does not marshal onto a component renderer. A delegate that reads or changes component state should use the owning component's InvokeAsync.
  • JavaScript cannot pass a .NET CancellationToken to this method. Capture an appropriate lifetime token in the delegate if the work must stop during teardown.
  • The wrapper does not own the DotNetObjectReference. Failing to unregister and dispose it keeps the delegate and captured services or component state alive.
  • Treat TInput as untrusted browser input. Revalidate identity, authorization, identifiers, limits, and business rules before returning sensitive data or performing work.

This adapter is intended for a single request/response callback shape. Components with several distinct operations are usually clearer with named [JSInvokable] instance methods.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Blazor.Utils.BlazorOutputInvoker:

Package Downloads
Soenneker.Blazor.Utils.InteropEventListener

Manages the registration, removal, and disposal of .NET object references used for interop event listeners.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1017 0 8/29/2026
4.0.1016 0 8/29/2026
4.0.1015 0 8/29/2026
4.0.1014 3,392 8/11/2026
4.0.1013 3,932 7/28/2026
4.0.1012 4,384 7/16/2026
4.0.1011 1,526 7/14/2026
4.0.1010 5,070 6/18/2026
4.0.1009 2,729 6/9/2026
4.0.1008 2,341 6/5/2026
4.0.1007 121 6/5/2026
4.0.1006 3,228 5/12/2026
4.0.1005 4,171 4/22/2026
4.0.1004 158 4/22/2026
4.0.1003 1,992 4/14/2026
4.0.1002 5,971 3/22/2026
4.0.1001 2,113 3/13/2026
4.0.1000 150 3/12/2026
4.0.999 144 3/12/2026
4.0.998 154 3/12/2026
Loading failed

Improve output invoker safety and README