© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
33 replies
fasadin

Chaining async methods. Method not found

I want to have something like this

        var foo = await new UserBuilder(_client)
            .CreateUser()
            .VerifyUser()
            .Build();
        var foo = await new UserBuilder(_client)
            .CreateUser()
            .VerifyUser()
            .Build();


but this gives me an error
Cannot resolve symbol 'VerifyUser'
Cannot resolve symbol 'VerifyUser'
it's because
CreateUser
CreateUser
returns
Task<T>
Task<T>


if I write like this

       var foo = await new UserBuilder(_client)
            .CreateUser();
        foo = await asd.VerifyUser();
        var bar = await asd.Build();
       var foo = await new UserBuilder(_client)
            .CreateUser();
        foo = await asd.VerifyUser();
        var bar = await asd.Build();


or like this

var asd = await (await (await new UserBuilder(_grupieClient)
            .CreateUser())
            .VerifyUser())
            .Build();
var asd = await (await (await new UserBuilder(_grupieClient)
            .CreateUser())
            .VerifyUser())
            .Build();


then it works as expected

but second and third solution it's ugly.

How to achieve desired syntax?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Calling async method
C#CC# / help
4y ago
✅ Reducing exception usage, async methods
C#CC# / help
2y ago