New to Telerik UI for Blazor? Download free 30-day trial

Increase the Blazor SignalR Max Message Size

Environment

Product Editor for Blazor,
FileManager for Blazor,
FileSelect for Blazor,
PdfViewer for Blazor,
Signature for Blazor

Description

This article applies only to Blazor Server apps. Blazor WebAssembly apps do not use SignalR between then browser and the .NET runtime.

How to increase the SignalR MaximumReceiveMessageSize in HubOptions of a Blazor Server application?

How to increase the maximum amount of characters supported by the Editor control?

How to increase the file size limit for FileManager download?

How to upload large files with the Telerik Blazor FileSelect?

How to display large PDF documents in the Blazor PDFViewer component?

Blazor Server apps use a SignalR WebSocket to communicate between the client (browser) and server. The SignalR WebSocket has a default maximum message size of 32 KB. A large Editor Value, FileSelect file size, or a PDFViewer Data can exceed the maximum SignalR message size, which will close the connection and abort the current application task.

Solution

Increase the MaximumReceiveMessageSize via HubOptions. The syntax and code placement can vary, depending on the .NET version or when the application was created. Here are a few possible alternatives.

Program.cs (.NET 6+)

using Microsoft.AspNetCore.SignalR;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddServerSideBlazor();

builder.Services.Configure<HubOptions>(options =>
{
    options.MaximumReceiveMessageSize = 1024 * 1024; // 1MB or use null
});

Use AddHubOptions in .NET 6+

builder.Services.AddServerSideBlazor().AddHubOptions(options => {
    options.MaximumReceiveMessageSize = null; // no limit or use a number
});

Startup.cs (.NET 3.1)

using Microsoft.AspNetCore.SignalR;

public void ConfigureServices(IServiceCollection services)
{
    services.AddServerSideBlazor();

    services.Configure<HubOptions>(options =>
    {
        options.MaximumReceiveMessageSize = 1024 * 1024; // 1MB or use null
    });
}

Use AddHubOptions in .NET 3.1

services.AddServerSideBlazor().AddHubOptions(options => {
    options.MaximumReceiveMessageSize = null; // no limit or use a number
});

Also see these Microsoft articles:

Notes

Make sure that AddServerSideBlazor() is called only once. All configuration settings in AddHubOptions and AddCircuitOptions must go together with this single statement.

See Also

In this article