© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
14 replies
blokyk

✅ Weird ASP0016 behavior

Is there a semantic difference between these two pieces of code? the first one is fine, but the second one gives me
ASP0016
ASP0016
(which i don't think is correct? it's late and i'm kind of an asp noob so i might be mistaken...). the only difference is that the lambda for
atomLinks.Select
atomLinks.Select
has
async/await
async/await
in the first one, but not in the second.

Code 1, async/await, no warning
app.MapGet("/molecule.xml", async context => {
    var atoms = await Task.WhenAll(
        atomLinks.Select(
            async (link) => await Utils.GetFeedAsync(link)
        )
    );
    var molecule = Utils.Aggregate(atoms);

    context.Response.ContentType = "application/atom+xml";
    using var bodyXmlWriter = XmlWriter.Create(context.Response.Body);
    molecule.SaveAsAtom10(bodyXmlWriter);
})
app.MapGet("/molecule.xml", async context => {
    var atoms = await Task.WhenAll(
        atomLinks.Select(
            async (link) => await Utils.GetFeedAsync(link)
        )
    );
    var molecule = Utils.Aggregate(atoms);

    context.Response.ContentType = "application/atom+xml";
    using var bodyXmlWriter = XmlWriter.Create(context.Response.Body);
    molecule.SaveAsAtom10(bodyXmlWriter);
})


Code 2, no async/await, gives ASP0016
app.MapGet("/molecule.xml", async context => {
    var atoms = await Task.WhenAll(
        atomLinks.Select(
            (link) => Utils.GetFeedAsync(link)
        )
    );
    var molecule = Utils.Aggregate(atoms);

    context.Response.ContentType = "application/atom+xml";
    using var bodyXmlWriter = XmlWriter.Create(context.Response.Body);
    molecule.SaveAsAtom10(bodyXmlWriter);
})
app.MapGet("/molecule.xml", async context => {
    var atoms = await Task.WhenAll(
        atomLinks.Select(
            (link) => Utils.GetFeedAsync(link)
        )
    );
    var molecule = Utils.Aggregate(atoms);

    context.Response.ContentType = "application/atom+xml";
    using var bodyXmlWriter = XmlWriter.Create(context.Response.Body);
    molecule.SaveAsAtom10(bodyXmlWriter);
})


(weirdly, the warning also goes away if i eta-reduce the lambda into just the
Utils.GetFeedAsync
Utils.GetFeedAsync
method group/name)

(also:
Compiler version: '5.0.0-2.25472.11 (b48cd5e8)'. Language version: 13.0.
Compiler version: '5.0.0-2.25472.11 (b48cd5e8)'. Language version: 13.0.
just in case)
ASP0016: Do not return a value from RequestDelegate
Learn about analysis rule ASP0016: Do not return a value from RequestDelegate
ASP0016: Do not return a value from RequestDelegate
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Weird ToBase64String behavior
C#CC# / help
4y ago
✅ powershell post MultipartContent weird behavior
C#CC# / help
4y ago
✅ Caesar Cipher Code with Weird Behavior
C#CC# / help
3y ago
❔ Weird performance behavior with sorting algorithms.
C#CC# / help
3y ago