tags:

views:

133

answers:

0

Possible Duplicate:
Compilation fails if delegate definitions is put in another project?

Using .NET 3.5 SP1 and Visual Studio 2008

Projects A and B, both class libraries, A uses B In project B i have the following:

public delegate void MyDelegate(object o1, EventArgs o2);
public delegate T MyUberDelegate<T>(MyDelegate myDelegate);

public class MyTestClass
{
    private MyUberDelegate<EventHandler> uberDelegate;
    public MyTestClass()
    {
        uberDelegate = h => (s, e) => h(s, e);
    }
}

This compiles, no problems. (uberDelegate returns an EventHandler which calls MyDelegate)

If i copy MyTestClass to project A, i get the following compile errors:

Error   1   Cannot convert lambda expression to delegate type 'MyUberDelegate<System.EventHandler>' because some of the return types in the block are not implicitly convertible to the delegate return type
Error   2   Delegate 'MyDelegate' does not take '2' arguments

If i alter MyTestClass to also include a field of type MyDelegate, it does work:

public class MyTestClass
{
    private MyUberDelegate<EventHandler> uberDelegate;
    private MyDelegate myDelegate;

    public MyTestClass()
    {
        uberDelegate = h => (s, e) => h(s, e);
    }
}

Why?

EDIT: duplicate of Compilation fails if delegate definitions is put in another project?