Note that there are some explanatory texts on larger screens.

plurals
  1. POImplicit delegate conversion not always working for delegates in another project?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/3276578/compilation-fails-if-delegate-definitions-is-put-in-another-project">Compilation fails if delegate definitions is put in another project?</a> </p> </blockquote> <p>Using .NET 3.5 SP1 and Visual Studio 2008</p> <p>Projects A and B, both class libraries, A uses B In project B i have the following:</p> <pre><code>public delegate void MyDelegate(object o1, EventArgs o2); public delegate T MyUberDelegate&lt;T&gt;(MyDelegate myDelegate); public class MyTestClass { private MyUberDelegate&lt;EventHandler&gt; uberDelegate; public MyTestClass() { uberDelegate = h =&gt; (s, e) =&gt; h(s, e); } } </code></pre> <p>This compiles, no problems. (uberDelegate returns an EventHandler which calls MyDelegate)</p> <p>If i copy MyTestClass to project A, i get the following compile errors:</p> <pre><code>Error 1 Cannot convert lambda expression to delegate type 'MyUberDelegate&lt;System.EventHandler&gt;' 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 </code></pre> <p>If i alter MyTestClass to also include a field of type MyDelegate, it does work:</p> <pre><code>public class MyTestClass { private MyUberDelegate&lt;EventHandler&gt; uberDelegate; private MyDelegate myDelegate; public MyTestClass() { uberDelegate = h =&gt; (s, e) =&gt; h(s, e); } } </code></pre> <p><strong>Why?</strong></p> <p>EDIT: duplicate of <a href="https://stackoverflow.com/questions/3276578/compilation-fails-if-delegate-definitions-is-put-in-another-project">Compilation fails if delegate definitions is put in another project?</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload