dotnet/machinelearning · error · NotSupportedException

The provided url ({uri}) redirects to the default url ({Defa

Error message

The provided url ({uri}) redirects to the default url ({DefaultUrl})

What it means

During resource download, ResourceManagerUtils (DownloadResource) checks whether an aka.ms URL's response actually redirects to Microsoft's default placeholder page. If so, the requested resource does not exist (aka.ms silently redirects dead links to the default page), and the code throws NotSupportedException with the redirecting URI and DefaultUrl in the message. This converts a silent 'wrong file downloaded' failure into an explicit error.

Source

Thrown at src/Microsoft.ML.Core/Utilities/ResourceManagerUtils.cs:276

                mutex.ReleaseMutex();
                return null;
            }

            Guid guid = Guid.NewGuid();
            string tempPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), "temp-resource-" + guid.ToString()));
            try
            {
                int blockSize = 4096;

                var response = await httpClient.GetAsync(uri, ct).ConfigureAwait(false);
                using (var fh = env.CreateOutputFile(tempPath))
                using (var ws = fh.CreateWriteStream())
                {
                    response.EnsureSuccessStatusCode();
                    IEnumerable<string> headers;
                    var hasHeader = response.Headers.TryGetValues("content-length", out headers);
                    if (uri.Host == "aka.ms" && IsRedirectToDefaultPage(uri.AbsoluteUri))
                        throw new NotSupportedException($"The provided url ({uri}) redirects to the default url ({DefaultUrl})");
                    if (!hasHeader || !long.TryParse(headers.First(), out var size))
                        size = 10000000;

                    var stream = await response.EnsureSuccessStatusCode().Content.ReadAsStreamAsync().ConfigureAwait(false);

                    await stream.CopyToAsync(ws, blockSize, ct);

                    if (ct.IsCancellationRequested)
                    {
                        ch.Error($"{fileName}: Download timed out");
                        return ch.Except("Download timed out");
                    }
                }
                File.Move(tempPath, path);
                ch.Info($"{fileName}: Download complete");
                return null;
            }
            catch (WebException e)

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Upgrade ML.NET to the latest version so the resource URL points to a live aka.ms link (Microsoft updates these when short links are retired).
  2. Pre-download the resource manually and place it in the expected cache file path so the downloader is not invoked.
  3. Inspect the thrown message's uri value and open it in a browser to confirm whether the link is dead; if dead, find the resource's current official URL.
  4. If behind a corporate proxy, exclude aka.ms from interception/rewriting or download from a trusted network.

Example fix

// before
// relying on bundled (stale) aka.ms URL that redirects to the default page
var path = await ResourceManagerUtils.Instance.EnsureResourceAsync(env, ch,
    relativeUrl, fileName, timeout);
// after
// check for update / pin a live URL
if (await IsRedirectToDefaultPageAsync(resourceUrl))
{
    throw new InvalidOperationException(
        $"Resource link {resourceUrl} is stale; upgrade ML.NET or download the model manually to {cachePath}.");
}
Defensive patterns

Strategy: try-catch

Validate before calling

using (var resp = await httpClient.GetAsync(resourceUrl, HttpCompletionOption.ResponseHeadersRead))
{
    var finalUri = resp.RequestMessage?.RequestUri;
    if (finalUri != null && resourceUrl.Contains("aka.ms") &&
        finalUri.ToString().StartsWith(defaultUrl, StringComparison.OrdinalIgnoreCase))
        throw new InvalidOperationException($"Resource link {resourceUrl} is dead (redirects to default page).");
}

Try / catch

try
{
    var path = await ResourceManagerUtils.Instance.EnsureResourceAsync(env, ch, relativeUrl, fileName, timeout);
}
catch (NotSupportedException ex) when (ex.Message.Contains("redirects to the default url"))
{
    // stale aka.ms link: upgrade ML.NET or download the resource manually to cachePath
}

Prevention

When it happens

Trigger: Requesting an aka.ms short link that no longer points to a real resource; a stale/renamed resource URL shipped in an older ML.NET version; network equipment (proxy, captive portal, DNS hijack) rewriting the aka.ms response so it looks like the default redirect page.

Common situations: Using an older ML.NET package whose baked-in model download URLs were retired by Microsoft; corporate proxies or firewalls intercepting short-link traffic and returning a landing/default page; typos in a custom aka.ms link passed to the resource manager.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/a1f3a8ea74e8eb38. Report an issue: GitHub.