RicoSuter/NSwag · error · InvalidOperationException

The ouput of is a 32-bit application and requires…

Error message

The ouput of {projectFile} is a 32-bit application and requires NSwag.Console.x86 to be processed.

What it means

When the target project is a .NET Framework project with PlatformTarget x86, the .NET Framework (NET462) build of NSwag must run as a 32-bit process to load the assembly. If the running NSwag process is 64-bit, RunAsync throws this error and tells the user to use the NSwag.Console.x86 tool instead, which is shipped as a separate 32-bit binary.

Solutions

  1. Run NSwag.Console.x86.exe instead of NSwag.Console.exe for this project.
  2. Change the project's PlatformTarget back to AnyCPU in the .csproj if 32-bit is not actually required.
  3. If using NSwag.MSBuild, configure the task to invoke the x86 variant of the tool.

Example fix

// before (64-bit tool)
nswag aspnetcore2openapi /project:LegacyApi.csproj
// after (x86 tool)
"C:\tools\nswag\NSwag.Console.x86.exe" aspnetcore2openapi /project:LegacyApi.csproj
Defensive patterns

Strategy: validation

Validate before calling

var isX86 = string.Equals(platformTarget, "x86", StringComparison.OrdinalIgnoreCase);
if (isX86 && Environment.Is64BitProcess)
    Console.WriteLine("Project is x86: use NSwag.Console.x86.exe instead.");

Try / catch

try
{
    await command.RunAsync(processor, host);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("NSwag.Console.x86"))
{
    // re-exec via the x86 tool binary
}

Prevention

When it happens

Trigger: Running the 64-bit NSwag.Console (or NSwag.MSBuild default) against a .csproj whose MSBuild PlatformTarget is 'x86', under the NET462 branch of AspNetCoreToOpenApiCommand.RunAsync while Environment.Is64BitProcess is true.

Common situations: A project was switched from AnyCPU to x86 (often to match native dependencies); using nswag.msbuild or the 64-bit Chocolatey/nuget console exe on such a project; 64-bit CI agents launching NSwag for 32-bit legacy Web API projects.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of RicoSuter/NSwag@63daf8fcc3 (2026-09-14). Data as JSON: /api/errors/7e0f1d4563d54a31. Report an issue: GitHub.

Appendix: source

Thrown at src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs:103

            var args = new List<string>();
            string executable;

#if NET462
            var toolDirectory = AppDomain.CurrentDomain.BaseDirectory;
            if (!Directory.Exists(toolDirectory))
            {
                toolDirectory = Path.GetDirectoryName(typeof(AspNetCoreToOpenApiCommand).GetTypeInfo().Assembly.Location);
            }

            if (projectMetadata.TargetFrameworkIdentifier == ".NETFramework")
            {
                string binaryName;
                var is32BitProject = string.Equals(projectMetadata.PlatformTarget, "x86", StringComparison.OrdinalIgnoreCase);
                if (is32BitProject)
                {
                    if (Environment.Is64BitProcess)
                    {
                        throw new InvalidOperationException($"The ouput of {projectFile} is a 32-bit application and requires NSwag.Console.x86 to be processed.");
                    }

                    binaryName = LauncherBinaryName + ".x86.exe";
                }
                else
                {
                    if (!Environment.Is64BitProcess)
                    {
                        throw new InvalidOperationException($"The ouput of {projectFile} is a 64-bit application and requires NSwag.Console to be processed.");
                    }

                    binaryName = LauncherBinaryName + ".exe";
                }

                var executableSource = Path.Combine(toolDirectory, binaryName);
                if (!File.Exists(executableSource))
                {
                    throw new InvalidOperationException($"Unable to locate {binaryName} in {toolDirectory}.");

View on GitHub (pinned to 63daf8fcc3)