dotnet/aspnetcore · error · IllegalArgumentException

A valid url is required.

Error message

A valid url is required.

What it means

HubConnectionBuilder.create(url) rejects a null or empty URL with IllegalArgumentException. The URL is the hub endpoint and is mandatory; without a valid URL the builder cannot construct a connection. This is a fail-fast precondition check.

Source

Thrown at src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnectionBuilder.java:18

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

package com.microsoft.signalr;

/**
 * A builder for configuring {@link HubConnection} instances.
 */
public abstract class HubConnectionBuilder {
    /**
     * Creates a new instance of {@link HttpHubConnectionBuilder}.
     *
     * @param url The URL of the SignalR hub to connect to.
     * @return An instance of {@link HttpHubConnectionBuilder}.
     */
    public static HttpHubConnectionBuilder create(String url) {
        if (url == null || url.isEmpty()) {
            throw new IllegalArgumentException("A valid url is required.");
        }
        return new HttpHubConnectionBuilder(url);
    }

    /**
     * Builds a new instance of {@link HubConnection}.
     *
     * @return A new instance of {@link HubConnection}.
     */
    public abstract HubConnection build();
}

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Provide a valid absolute hub URL such as https://host/hub.
  2. Null/empty-check the resolved config value before calling create() and fail fast with a clear message.
  3. Validate the URL format at app startup rather than at first connection.

Example fix

// before
HubConnection conn = HubConnectionBuilder.create(url).build();

// after
if (url == null || url.trim().isEmpty()) {
    throw new IllegalStateException("SignalR hub URL is not configured");
}
HubConnection conn = HubConnectionBuilder.create(url).build();
Defensive patterns

Strategy: validation

Validate before calling

// Java
if (url == null || url.trim().isEmpty()) {
    throw new IllegalStateException("SignalR hub URL is not configured");
}
HubConnectionBuilder.create(url);

Try / catch

try {
    HubConnectionBuilder.create(url);
} catch (IllegalArgumentException ex) {
    // surface configuration error clearly
}

Prevention

When it happens

Trigger: Passing null, "", or a whitespace-only string to HubConnectionBuilder.create(); reading the URL from a config property/environment variable that resolved to null; building the URL via string concatenation with a null field.

Common situations: Missing environment variable or appsettings key; property typo; URL field not injected (DI/serialization left it null); build-time placeholder never replaced.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/c3083ee8fcb81dd8. Report an issue: GitHub.