dotnet/BenchmarkDotNet · error · NotSupportedException

Missing extension on source '{source}', must have the extens

Error message

Missing extension on source '{source}', must have the extension '.dll' or '.exe'.

What it means

ValidateSourceIsAssemblyOrThrow throws NotSupportedException (via Path.HasExtension returning false) when the source string has no extension. The adapter only accepts benchmark assemblies with a '.dll' or '.exe' extension; an extension-less path cannot be a managed assembly.

Source

Thrown at src/BenchmarkDotNet.TestAdapter/VSTestAdapter.cs:237

#if NETFRAMEWORK
            var appBase = Path.GetDirectoryName(assemblyPath);
            var setup = new AppDomainSetup { ApplicationBase = appBase };
            var domainName = $"Isolated Domain for {type.Name}";
            var appDomain = AppDomain.CreateDomain(domainName, null, setup);
            return appDomain.CreateInstanceAndUnwrap(
                type.Assembly.FullName, type.FullName, false, BindingFlags.Default, null, null, null, null);
#else
            return Activator.CreateInstance(type);
#endif
        }

        private static void ValidateSourceIsAssemblyOrThrow(string source)
        {
            if (string.IsNullOrEmpty(source))
                throw new ArgumentException($"'{nameof(source)}' cannot be null or whitespace.", nameof(source));

            if (!Path.HasExtension(source))
                throw new NotSupportedException($"Missing extension on source '{source}', must have the extension '.dll' or '.exe'.");

            var extension = Path.GetExtension(source);
            if (!string.Equals(extension, ".dll", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".exe", StringComparison.OrdinalIgnoreCase))
                throw new NotSupportedException($"Unsupported extension on source '{source}', must have the extension '.dll' or '.exe'.");
        }
    }
}

View on GitHub (pinned to b515068b61)

Solutions

  1. Point the adapter at the compiled assembly file (e.g. bin/Debug/net8.0/MyBenchmarks.dll).
  2. If you only have a project path, build it first and resolve the output .dll/.exe.
  3. Fix the calling code/tool that is dropping the extension.

Example fix

// before
var source = "MyBenchmarks"; // no extension -> throws

// after
var source = "bin/Debug/net8.0/MyBenchmarks.dll";
Defensive patterns

Strategy: validation

Validate before calling

static string RequireAssemblyPath(string source)
{
    if (!Path.HasExtension(source))
        throw new ArgumentException($"source '{source}' must be a .dll/.exe", nameof(source));
    return source;
}

Prevention

When it happens

Trigger: Source passed without a file extension, e.g. a directory path or a malformed filename like 'MyBenchmarks' (no '.dll'). Path.HasExtension returns false.

Common situations: Passing a project/output directory instead of the assembly file; a typo or truncated path; tooling that strips the extension before forwarding to the adapter.

Related errors


AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13). Data as JSON: /api/errors/58b3b290ff09685a. Report an issue: GitHub.