Skip to content

Build error in 5.6.1 when command depends on a CancellationToken from ConsoleAppFramework #199

@djeikyb

Description

@djeikyb

In version 5.6.1, I'm getting a build error when trying to use an async command with a CancellationToken. Version 5.5.0 builds just fine, so I'm suspecting it's a bug?

error CS0103: The name '__ExternalCancellationToken__' does not exist in the current context

full repo

/Users/jacob/dev/me/active/CafSample/obj/Debug/net9.0/ConsoleAppFramework/ConsoleAppFramework.ConsoleAppGenerator/ConsoleApp.Run.g.cs(30,77): error CS0103: The name '__ExternalCancellationToken__' does not exist in the current context

The build failed. Fix the build errors and run again.
using ConsoleAppFramework;

await ConsoleApp.RunAsync(args, Commands.Save);

static class Commands
{
    /// <summary>
    /// Some sort of save command.
    /// </summary>
    public static async Task<int> Save(CancellationToken ct)
    {
        await Task.Delay(1000);
        return 0;
    }
}

Same result with:

using System.Threading;
using System.Threading.Tasks;
using ConsoleAppFramework;

await ConsoleApp.RunAsync(args, async (CancellationToken ct) => await Task.Delay(1000, ct));

I tried running in a docker container (mcr.microsoft.com/dotnet/sdk:9.0) to avoid any weirdness with early releases of dotnet 10 I've installed.

root@78e35801fe2e:/src# rm -fr {bin,obj] ; dotnet run
/src/obj/Debug/net9.0/ConsoleAppFramework/ConsoleAppFramework.ConsoleAppGenerator/ConsoleApp.Run.g.cs(28,77): error CS0103: The name '__ExternalCancellationToken__' does not exist in the current context

The build failed. Fix the build errors and run again.

root@78e35801fe2e:/src# dotnet --info
.NET SDK:
 Version:           9.0.306
 Commit:            cc9947ca66
 Workload version:  9.0.300-manifests.87361a52
 MSBuild version:   17.14.28+09c1be848

Runtime Environment:
 OS Name:     debian
 OS Version:  12
 OS Platform: Linux
 RID:         linux-arm64
 Base Path:   /usr/share/dotnet/sdk/9.0.306/

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.10
  Architecture: arm64
  Commit:       e1f19886fe

.NET SDKs installed:
  9.0.306 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions