Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this object's type show no interfaces via reflection, despite implementing at least two?
    primarykey
    data
    text
    <p>First, an example of something that works as expected: (all code was executed in VS2008 immediate window)</p> <pre><code>25 is IComparable &gt;&gt; true 25.GetType().GetInterfaces() &gt;&gt; {System.Type[5]} &gt;&gt; [0]: {Name = "IComparable" FullName = ... &gt;&gt; [1]: {Name = "IFormattable" FullName = ... &gt;&gt; ... </code></pre> <p>So far so good. Now let's try on an object where the interface is inherited via a base type:</p> <pre><code>class TestBase : IComparable { public int CompareTo(object obj) { throw new NotImplementedException(); } } class TheTest : TestBase { } </code></pre> <p>In the immediate window:</p> <pre><code>(new TheTest()) is IComparable &gt;&gt; true (new TheTest()).GetType().GetInterfaces() &gt;&gt; {System.Type[1]} &gt;&gt; [0]: {Name = "IComparable" FullName = "System.IComparable"} </code></pre> <p>No surprises here either. How come the following code doesn't show any interfaces then:</p> <pre><code>wcfChannel = ChannelFactory&lt;IMyServiceApi&gt;.CreateChannel(binding, endpointAddress); wcfChannel is IMyServiceApi &amp;&amp; wcfChannel is ICommunicationObject &gt;&gt; true typeof(IMyServiceApi).IsInterface &amp;&amp; typeof(ICommunicationObject).IsInterface &gt;&gt; true wcfChannel.GetType().GetInterfaces() &gt;&gt; {System.Type[0]} </code></pre> <p>How can all of the above be true at the same time?</p> <p>(<strong>edit</strong>: added <code>wcfChannel is ICommunicationObject</code> above, which is at this time unexplained by the answer that explains how <code>wcfChannel is IMyServiceApi</code> is true.)</p>
    singulars
    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