Does implicit delegate conversion not always work for delegates in another project?

Possible duplicate:
Compilation error if delegate definitions are placed 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); } } 

It compiles, no problem. (uberDelegate returns an EventHandler that calls MyDelegate)

If I copy MyTestClass to project A, I get the following compilation 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 modify MyTestClass to also include a field of type MyDelegate, it works:

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

Why?

EDIT: duplicate Compilation error if delegate definitions are placed in another project?

+4
source share

All Articles