title: How can I debug my Xamarin app when it only breaks in release mode?
body: <p>I recently discovered that when I ran my app on the android version in release mode my 'Specialty' drop down option field was empty with no options to change to. The problem is that it's hard to debug the issue because I can't step through my code and analyse variable values prior to the issue. I have searched for days for any way of seeing the values by either writing to console, making files with strings in them etc but no luck.</p>
  
  <p>Luckily I managed to locate the line of the issue by using alertdisplays which didn't show up but did crash the app if they were shown, so I was able to see how high up i could put the alertdisplay in my try catch statement before it would crash the app. If there was no crash it suggested that the try statement must have switched to the catch at the line before the alert display.</p>
  
  <p>A few things to note:</p>
  
  <ul>
  <li>It only breaks on android release mode</li>
  <li>It works fine on IOS release and debug mode</li>
  <li>Release mode works on android if I enable shared mono runtime (but this means I can't publish the app)</li>
  <li>Debug mode works regardless of whether shared mono runtime is used</li>
  <li>I've tried both on a physical and virtual device for android, same outcome</li>
  </ul>
  
  <p>Here is the try catch statement which is meant to retrieve a list of specialties from a uri (putting the uri into my search bar shows me a correct list of specialties) which catches an exception:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>/// Summary: Gets the specialty list 
  /// Returns: JArray of specialties   
  public async Task&lt;string&gt; getSpecialtyAsync()
  {
      HttpClient client = new HttpClient();
      var uri = new Uri(string.Format("https://medphys.royalsurrey.nhs.uk/space/tools/web_services.php?cmd=getSpecialtyList", string.Empty));            
      try
      {
          var response = await client.GetAsync(uri); //This line seems to cause the catch to fire
          if (response.IsSuccessStatusCode)
          {
              var content = await response.Content.ReadAsStringAsync();
              return content;
          }
  
      }
      catch (Exception ex)
      {
          //How do i print out the exception here, along with some variable values?
      }           
      return null;
  }
  </code></pre>
  
  <p>This appears in the console when I press the search button with an empty Specialty field:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[MonoDroid] UNHANDLED EXCEPTION:
  [MonoDroid] System.InvalidCastException: Specified cast is not valid.
  [MonoDroid]   at SPACE.PathwaySearch..ctor (System.String searchTerm) [0x00079] in &lt;a380d4923fda450eadc5c42fb0c107d2&gt;:0 
  [MonoDroid]   at SPACE.SearchPage+&lt;&gt;c__DisplayClass1_0.&lt;.ctor&gt;b__2 (System.Object s, System.EventArgs e) [0x00167] in &lt;a380d4923fda450eadc5c42fb0c107d2&gt;:0 
  [MonoDroid]   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+&lt;&gt;c.&lt;ThrowAsync&gt;b__7_0 (System.Object state) [0x00000] in &lt;a49690ecb3764be9bb02bbcc2d264f28&gt;:0 
  [MonoDroid]   at Android.App.SyncContext+&lt;&gt;c__DisplayClass2_0.&lt;Post&gt;b__0 () [0x00000] in &lt;6eddb440f9714f0591fc9a4fcb875afa&gt;:0 
  [MonoDroid]   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in &lt;6eddb440f9714f0591fc9a4fcb875afa&gt;:0 
  [MonoDroid]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in &lt;6eddb440f9714f0591fc9a4fcb875afa&gt;:0 
  [MonoDroid]   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.35(intptr,intptr)
  [alPhysics.SPAC] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
  [AndroidRuntime] Shutting down VM
  [AndroidRuntime] FATAL EXCEPTION: main
  [AndroidRuntime] Process: com.NHS.rsch.MedicalPhysics.SPACE, PID: 13871
  [AndroidRuntime] android.runtime.JavaProxyThrowable: System.InvalidCastException: Specified cast is not valid.
  [AndroidRuntime]   at SPACE.PathwaySearch..ctor (System.String searchTerm) [0x00079] in &lt;a380d4923fda450eadc5c42fb0c107d2&gt;:0 
  [AndroidRuntime]   at SPACE.SearchPage+&lt;&gt;c__DisplayClass1_0.&lt;.ctor&gt;b__2 (System.Object s, System.EventArgs e) [0x00167] in &lt;a380d4923fda450eadc5c42fb0c107d2&gt;:0 
  [AndroidRuntime]   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+&lt;&gt;c.&lt;ThrowAsync&gt;b__7_0 (System.Object state) [0x00000] in &lt;a49690ecb3764be9bb02bbcc2d264f28&gt;:0 
  [AndroidRuntime]   at Android.App.SyncContext+&lt;&gt;c__DisplayClass2_0.&lt;Post&gt;b__0 () [0x00000] in &lt;6eddb440f9714f0591fc9a4fcb875afa&gt;:0 
  [AndroidRuntime]   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in &lt;6eddb440f9714f0591fc9a4fcb875afa&gt;:0 
  [AndroidRuntime]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in &lt;6eddb440f9714f0591fc9a4fcb875afa&gt;:0 
  [AndroidRuntime]   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.35(intptr,intptr)
  [AndroidRuntime]    at mono.java.lang.RunnableImplementor.n_run(Native Method)
  [AndroidRuntime]    at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
  [AndroidRuntime]    at android.os.Handler.handleCallback(Handler.java:873)
  [AndroidRuntime]    at android.os.Handler.dispatchMessage(Handler.java:99)
  [AndroidRuntime]    at android.os.Looper.loop(Looper.java:193)
  [AndroidRuntime]    at android.app.ActivityThread.main(ActivityThread.java:6669)
  [AndroidRuntime]    at java.lang.reflect.Method.invoke(Native Method)
  [AndroidRuntime]    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
  [AndroidRuntime]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>