c# - Unreachable Code Warning in Static EventHandler callback -


we have interesting issue occurring wonder if may able shed light on. seeing warning: "method never reaches end or 'return' statement" on event handler delegate callback rather odd.

consider following code (you can ignore scb_ functions, not relevant question):

public static class nativebridge {     private static unityeventqueue _eventqueue;     private static bool _initialized;      public static void init()      {         if (_initialized)         {             return;         }         _initialized = true;         scb_sdkinit();         _eventqueue = unityeventqueue.instance;         _eventqueue.appexiting += eventqueue_appexiting;         scb_registerreceivedsistrcallback(sistrreceived);     }      //lots of other irrelevant code      private static void eventqueue_appexiting(object sender, eventargs e)     {         scb_registerreceivedsistrcallback(null);         _eventqueue.appexiting -= eventqueue_appexiting;         scb_sdkfinal();         _initialized = false;     }  } 

the warning on eventqueue_appexiting. here odd part. if comment out unregistration, _eventqueue.appexiting -= eventqueue_appexiting, warning disappears.

we have tried variety of "solutions" seems bug in unreachability pass of compiler:

  1. make static class, non-static , adjust accordingly
  2. make event in unityenginequeue static, , adjust accordingly
  3. place event un-registration @ end of callback method
  4. comment out calls void scb_ functions sanity check
  5. various other spaghetti @ wall solutions

all of above yielded no change in compiler's behavior. our best guess compiler detects unregistration , thinks because delegate removed, cannot complete execution @ runtime, though believe stack have continue execution after removal because invocation had begun.

it not seem having adverse effect in application's execution, difficult debug due nature of event's invocation conditions (application exiting).

what complier seeing and/or potentially doing wrong?

p.s. bit of context, class static because acts extern bridge various platform specific libraries similar api. fact has little question, quell "ewwww static class" sentiment.

i think bug reported on link:

https://bugzilla.xamarin.com/show_bug.cgi?id=42819

and here

https://bugzilla.xamarin.com/show_bug.cgi?id=41798

they report fixed in version 6.2.0.259


Comments