adrianm
adrianm

Reputation: 14726

Strange C# compiler error

Can someone help me sort out this compiler error?

I have a class like this

public class Test {
    public delegate void TestAction<T>(T arg);
    public delegate void TestActionCaller<T1, T2>(T1 arg, TestAction<T2> action);

    public static void Call<T1,T2>(TestActionCaller<T1,T2> actioncaller) {
        actioncaller(default(T1), arg => { });
    }
}

Then I have the following code

public class TestCaller {
    static TestCaller() {
        Test.Call<int, int>((arg,action)=>action(arg));
    }
}

This works fine.

But if I move the TestCaller to another assembly (exactly the same code as above) I get a compiler error "Delegate 'TestAction' does not take '1' arguments."

Upvotes: 1

Views: 167

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038800

I believe the compiler cannot infer parameters and you need to specify their type explicitly:

Test.Call((int arg, TestAction<int> action) => action(arg));

Upvotes: 2

Related Questions