Skip to content

Analyse dependencies of async lambdas #230

Description

@penenkel

Summary

It seems as if the dependencies of async lambda functions are not enumerated correctly.

Scenario

Consider a class C2 that calls a method on class C1 and passes a lambda function which calls a method on class C3.

    class C1 { 
        public void Register(Func<Task> action) { } 
    }
    class C2 { 
        void Foo(C1 b1) { 
            b1.Register(() => { C3.Bar1(); return Task.CompletedTask; });
            b1.Register(async () => { C3.Bar2(); await Task.CompletedTask; });
        } 
    }
    class C3 { 
        public static void Bar1() { }
        public static void Bar2() { }
    }

I encountered this in the context of AspNetCore MinimalApi endpoint registrations thus the convoluted example. It is probable that the problem could be reproduced with a simpler example.

Expectation

Then I would expect the following test to successfully verify that both methods C3.Bar1 and C3.Bar2 are called from within C2.

    [Fact]
    public void ShouldDetectCallsInLambdas()
    {
        var architecture = new ArchLoader().LoadAssemblies([GetType().Assembly]).Build();

        var rule1 = Types().That().Are(typeof(C2)).Should().CallAny("C3::Bar1", true);
        var rule2 = Types().That().Are(typeof(C2)).Should().CallAny("C3::Bar2", true);
        var rule = rule1.And(rule2);

        rule.Check(architecture);
    }

Actual result

But it fails to do so for Bar2 which is called from an async lambda. This probably due to the compiler generated state-machine, similar to #138.

Activity

  1. added 2 commits that reference this issue on Oct 7, 2026
    6ca88f7
    20eadca
  2. added a commit that references this issue on Oct 9, 2026
    6668c4c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions