Repository navigation
Description
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]
#endiffixes 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.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Mar 11, 2026
Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.
[-]SDK 11 breaks net10 async runtime[/-][+]SDK 11 breaks build for net10 using async runtime features[/+]huoyaoyuan commentedon Mar 11, 2026
This should not be the case for preview features. There can be breaking changes in the tooling, especially for early previews.
mgravell commentedon Mar 11, 2026
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.dotnet-policy-service commentedon Mar 11, 2026
Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.
hez2010 commentedon Mar 12, 2026
You can suppress it by adding
as a temporary workaround.
jkotas commentedon Mar 12, 2026
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.
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.
mgravell commentedon Mar 12, 2026
Fine. But IMO this should be very clear in #109632, for example:
or (whichever is correct)
jkotas commentedon Mar 12, 2026
Updated #109632
We do not plan to fully enable this feature automatically in .NET 11.
mgravell commentedon Mar 12, 2026
Thanks. That is clearer.