OrchardCMS/OrchardCore · error · InvalidOperationException

The media path is invalid.

Error message

The media path is invalid.

What it means

MetaWeblog's newMediaObject (XML-RPC media upload) normalizes the provided media file name via IMediaFileStore.NormalizePath and rejects empty/whitespace results with 'The media path is invalid.'. This validates that a usable, non-empty target path was supplied before writing to the Media File Store.

Solutions

  1. Ensure the media struct in the newMediaObject request includes a non-empty 'name' field with the target file name/path
  2. Fix the blogging client's media upload settings so it sends file names
  3. If calling the API directly, pass e.g. 'image.png' or 'subfolder/image.png' as name

Example fix

// before
var file = new { bits = File.ReadAllBytes("img.png") };
// after
var file = new { name = "img.png", bits = File.ReadAllBytes("img.png") };
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(media.name)) throw new ArgumentException("newMediaObject requires a non-empty 'name'");

Type guard

bool HasValidMediaName(IDictionary<string, object> file) => file.TryGetValue("name", out var n) && n is string s && !string.IsNullOrWhiteSpace(s);

Try / catch

try { await client.NewMediaObjectAsync(blogId, user, pass, media); } catch (InvalidOperationException ex) when (ex.Message.Contains("media path is invalid")) { FixMediaNameAndRetry(media); }

Prevention

When it happens

Trigger: Sending an XML-RPC metaWeblog.newMediaObject request whose media struct has a missing, null, or empty/whitespace 'name' field.

Common situations: Blog clients (Open Live Writer, MarsEdit-like tools) configured to upload media without a filename; hand-written XML-RPC calls omitting 'name'; clients sending only 'bits'.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/6085c503a5d7de92. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs:164

            var result = await MetaWeblogNewMediaObjectAsync(
                Convert.ToString(context.RpcMethodCall.Params[1].Value),
                Convert.ToString(context.RpcMethodCall.Params[2].Value),
                (XRpcStruct)context.RpcMethodCall.Params[3].Value);
            context.RpcMethodResponse = new XRpcMethodResponse().Add(result);
        }
    }

    private async Task<XRpcStruct> MetaWeblogNewMediaObjectAsync(string userName, string password, XRpcStruct file)
    {
        var user = await ValidateUserAsync(userName, password);

        var name = file.Optional<string>("name");
        var bits = file.Optional<byte[]>("bits");

        var normalizedPath = _mediaFileStore.NormalizePath(name);
        if (string.IsNullOrWhiteSpace(normalizedPath))
        {
            throw new InvalidOperationException(S["The media path is invalid."].Value);
        }

        var pathSegments = normalizedPath.Split('/', StringSplitOptions.RemoveEmptyEntries);
        if (pathSegments.Any(segment => segment is "." or ".."))
        {
            throw new InvalidOperationException(S["The media path is invalid."].Value);
        }

        var fileName = pathSegments[^1];
        var directoryName = string.Join('/', pathSegments[..^1]);
        var filePath = _mediaFileStore.Combine(directoryName, fileName);

        if (!await _authorizationService.AuthorizeAsync(user, MediaPermissions.ManageMedia)
            || !await _authorizationService.AuthorizeAsync(user, MediaPermissions.ManageMediaFolder, (object)(directoryName ?? string.Empty)))
        {
            throw new InvalidOperationException(S["Not authorized to upload media."].Value);
        }

View on GitHub (pinned to 4306c0717f)