Skip to content

SDK 11 breaks build for net10 using async runtime features #125427

Closed

Description

@mgravell

Description

(note: the underlying problem is probably shown in the "Known Workarounds" section)

After installing .NET 11 preview 2, I am unable to run async-runtime samples that target .NET 10. Samples that target .NET 11 work, but I am unclear whether the new flags are required for that.

Reproduction Steps

Demo with a trivial .NET 10 console exe, ala dotnet new console:

cs:

await Task.Delay(100);
Console.WriteLine("Hello, World!");

csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <!-- the interesting bits -->
    <EnablePreviewFeatures>true</EnablePreviewFeatures>
    <LangVersion>preview</LangVersion>
    <Features>$(Features);runtime-async=on</Features>
    <SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
    <NoWarn>$(NoWarn);SYSLIB5007</NoWarn>
  </PropertyGroup>
</Project>

env:

$env:DOTNET_RuntimeAsync = 1

global.json

{
  "sdk": {
    "version": "10.0.102",
  }
}

OK, that builds, no problem!

➜ dotnet run
Hello, World!

Now, the break: we change the build SDK and nothing else:

{
  "sdk": {
    "version": "11.0.100-preview.2.26159.112"
  }
}

and try again, again still targeting .NET 10:

➜ dotnet run
C:\Code\runtimeasync\Program.cs(1,1): error CA2252: Using 'Await' requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Expected behavior

The .NET 11 SDK respects the historic behaviour of "I can still build old setups", i.e. it can build async-runtime code for both .NET 10 and .NET 11 targets

Actual behavior

Build fails

Regression?

Yes, the same .NET 10 build worked with SDK 10, but not with SDK 11.

Known Workarounds

It looks like manually adding:

#if NET10_0
[assembly:System.Runtime.Versioning.RequiresPreviewFeatures]
#endif

fixes things... maybe the problem is <EnablePreviewFeatures>true</EnablePreviewFeatures> when targeting net10.0 from SDK 11 isn't generating the right output? The additional #if here is required for me to then use <TargetFrameworks>net10.0;net11.0</TargetFrameworks> without getting

Error CS0579: Duplicate 'System.Runtime.Versioning.RequiresPreviewFeaturesAttribute' attribute

on the .NET 11 build, highlighting the output difference from <EnablePreviewFeatures> on SDK 11 targeting .NET 10 vs .NET 11.

Configuration

No response

Other information

My goal here is to setup a multi-targeted test project that targets .NET 10 and .NET 11 and exercises the new async runtime features side-by-side, on/off, etc.

Activity

  1. added
    untriaged
    on Mar 11, 2026
  2. dotnet-policy-service commented on Mar 11, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-meta
    See info in area-owners.md if you want to be subscribed.

  3. changed the title [-]SDK 11 breaks net10 async runtime[/-] [+]SDK 11 breaks build for net10 using async runtime features[/+] on Mar 11, 2026
  4. huoyaoyuan commented on Mar 11, 2026

    @huoyaoyuan
    Member

    The .NET 11 SDK respects the historic behaviour of "I can still build old setups"

    This should not be the case for preview features. There can be breaking changes in the tooling, especially for early previews.

  5. mgravell commented on Mar 11, 2026

    @mgravell
    ContributorAuthor

    I'm a little sympathetic to that perspective @huoyaoyuan, but if that is the case, the "how to" stuff should at least be up-to-date with the new SDK - hence my poke on 109632 immediately above. If the problem was related to changes in the API/IL surface of the async layer and not wanting to maintain compiler support for an abandoned out-of-date preview-only spike: fine, I can get behind that. But if (as per workarounds) the error is just around emitting [assembly:RequiresPreviewFeatures] correctly: it is harder to justify, IMHO.

  6. dotnet-policy-service commented on Mar 11, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke
    See info in area-owners.md if you want to be subscribed.

  7. hez2010 commented on Mar 12, 2026

    @hez2010
    Contributor

    You can suppress it by adding

    <NoWarn>$(NoWarn);CA2252</NoWarn>

    as a temporary workaround.

  8. jkotas commented on Mar 12, 2026

    @jkotas
    Member

    The behavior you are seeing is by design. From https://aka.ms/dotnet-warnings/preview-features doc:

    Since preview features between runtime, framework, and tooling are usually in support of each other, you can't expect to use, say, the .NET 7 SDK to build for .NET 6 when using preview features. This is likely counter intuitive because SDKs are usually backwards compatible, but it's really no different from the framework, which is also backwards compatible but not for preview features.

    if (as per workarounds) the error is just around emitting [assembly:RequiresPreviewFeatures] correctly: it is harder to justify, IMHO.

    There is nothing to justify. We do not want to be spending time on creative workarounds to try to make version mix-and-match work with preview features.

  9. mgravell commented on Mar 12, 2026

    @mgravell
    ContributorAuthor

    Fine. But IMO this should be very clear in #109632, for example:

    Preview in .NET 11

    The same steps should be used as per .NET 10 above, but: the project must target net11.0; the .NET 11 SDK cannot be used to build runtime-async features against net10.0 targets.

    or (whichever is correct)

    In .NET 11

    The feature is fully enabled automatically in .NET 11; no additional setup is required.

  10. jkotas commented on Mar 12, 2026

    @jkotas
    Member

    Updated #109632

    The feature is fully enabled automatically in .NET 11; no additional setup is required.

    We do not plan to fully enable this feature automatically in .NET 11.

  11. mgravell commented on Mar 12, 2026

    @mgravell
    ContributorAuthor

    Thanks. That is clearer.

  12. removed
    untriaged
    on Mar 12, 2026
  13. locked and limited conversation to collaborators on Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions