Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Type.GetInterfaces() sometimes not return a valid list?
    text
    copied!<p>We inherited a somewhat poorly-designed WCF service that we want to improve. One problem with it is that it has over a hundred methods (on two different interfaces), most of which we suspect are not used. We decided to put some logging on each of the methods to track when and how they're called. To make the tracing code refactor-friendly and typo-proof, we implemented it like so:</p> <pre><code>public void LogUsage() { try { MethodBase callingMethod = new StackTrace().GetFrame(1).GetMethod(); string interfaceName = callingMethod.DeclaringType.GetInterfaces()[0].Name; _loggingDao.LogUsage(interfaceName, callingMethod.Name, GetClientAddress(), GetCallingUrl()); } catch (Exception exception) { _legacyLogger.Error("Error in usage tracking", exception); } } </code></pre> <p><code>LogUsage()</code> is then called at the start of each method we want to trace.</p> <p>The service is very high traffic, on the order of 500,000+ calls/day. 99.95% of the time, this code executes beautifully. But the other 0.05% of the time, <code>GetInterfaces()</code> returns an empty (but not <code>null</code>) array. </p> <p><strong>Why would <code>GetInterfaces()</code> occasionally return inconsistent results?</strong></p> <p>This may seem so trivial - a 0.05% error rate is something we can usually only dream of. But the whole point is to identify <strong>all</strong> the service touchpoints, and if this error is always coming out of one (or a few) method calls, then our tracing is incomplete. I've tried to reproduce this error in my development environment by calling each and every method on the service, but to no avail.</p>
 

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