Bug 21977 - Compiler ignores comment //
Summary: Compiler ignores comment //
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.14.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-08-09 08:29 UTC by djnonsens
Modified: 2015-01-20 04:39 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
This image shows the problem (471.04 KB, image/png)
2014-08-09 08:30 UTC, djnonsens
Details
This image shows the same problem with collapsed error message (445.63 KB, image/png)
2014-08-09 08:42 UTC, djnonsens
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description djnonsens 2014-08-09 08:29:02 UTC
I just upgraded to Xamarin Studio 5.2 (build 386) and opened the project that I am currently working on. Running the project, I get an "Object reference not set to an instance of an object" on a line that should be ignored, because it has been commented out:

//_btnButton.Click += HandleClick;

This is the code of the problematic Fragment. Note that I changes some code because of security reasons, but I left all comments in tact, because I believe this is due to a regex problem

[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Locations;

using NeedToRun.Core;
using System.Threading.Tasks;
using Android.Views.InputMethods;
using System.Threading;

namespace NeedToRun.Droid {
	public class SearchFragment : BaseFragment  {
		public override void OnCreate (Bundle savedInstanceState) {
			Console.WriteLine ("SearchFragment OnCreate()");
			base.OnCreate (savedInstanceState);
		}

		private TextView _titleLabel;
		private SearchEditText _searchFrom;
		private SearchEditText _searchTo;
		private Button _searchButton;
		private ProgressBar _progressSearch;


		private AlertDialog _dialog; //TODO: dispose me?
		private StateManager stateManager;

		private LocationBase[] _locations;

		private Button _btnTest;
		//private Button _btnButton;

		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			Console.WriteLine ("SearchFragment OnCreateView()");
			base.OnCreateView (inflater, container, savedInstanceState);

			Activity.Window.SetSoftInputMode (SoftInput.StateHidden);

			stateManager = StateManager.Instance;
			var view = (ViewGroup)inflater.Inflate (Resource.Layout.Search, container, false);

			_titleLabel = view.FindViewById<TextView> (Resource.Id.textTitle);
			_searchFrom = view.FindViewById<SearchEditText> (Resource.Id.searchEditTextFrom);
			_searchTo = view.FindViewById<SearchEditText> (Resource.Id.searchEditTextTo);
			_progressSearch = view.FindViewById<ProgressBar> (Resource.Id.progressSearch);
			_searchButton = view.FindViewById<Button> (Resource.Id.btnSearch);

			_titleLabel.Typeface = AssetManager.FontBebas;

			_btnTest = view.FindViewById<Button> (Resource.Id.btnTest);
			//btnButton = view.FindViewById<Button> (Resource.Id.btnButton);

			return view;
		}

		public override void OnPause () {
			Console.WriteLine ("SearchFragment OnPause");

			base.OnPause ();

			_searchFrom.SearchClick -= HandleSearchFromButtonClick;
			_searchFrom.EditorAction -= HandleSearchEditorAction;
			_searchTo.SearchClick -= HandleSearchToButtonClick;
			_searchTo.EditorAction -= HandleSearchEditorAction;

			_searchButton.Click  -= HandleSearchButtonClick;

			_btnTest.Click -= HandleTestClick;
			HideKeyboards ();
		}

		public override void OnResume () {
			Console.WriteLine ("SearchFragment OnResume");

			_searchFrom.SearchClick += HandleSearchFromButtonClick;
			_searchTo.SearchClick += HandleSearchToButtonClick;
			_searchFrom.EditorAction += HandleSearchEditorAction;
			_searchTo.EditorAction += HandleSearchEditorAction;

			_searchButton.Click += HandleSearchButtonClick;
			//_searchButton.Touch += HandleSearchButtonTouch;
 			//_btnButton.Click += HandleClick;


			_btnTest.Visibility = ViewStates.Invisible;

			#if DEBUG
			_btnTest.Visibility = ViewStates.Visible;
			#endif

			_btnTest.Click += HandleTestClick;

			base.OnResume ();
		}

		async void HandleClick (object sender, EventArgs e) {
			var njaa = await DoStuff ();
			njaa.ToString ();
		}

		private async Task<bool> DoStuff() {
			Func<bool> doStuffJob = new Func<bool>(() => DoStuffJob());
			return await Task.Run<bool>(doStuffJob);
		}

		private bool DoStuffJob() {
			Double value = 0;

			for (int i = 0; i < 30000000; i++)
				value += Math.Log(Math.Sqrt(Math.Pow(value, 0.75)));

			return true;
		}

		void HideKeyboards() {
			HideKeyboard (Activity, _searchFrom.WindowToken);
			HideKeyboard (Activity, _searchTo.WindowToken);
		}

		async void HandleSearchEditorAction (object sender, TextView.EditorActionEventArgs e) {
			Console.WriteLine ("HandleSearchEditorAction");

			var editText = (EditText)sender;

			if ((e.ActionId == ImeAction.Done) || (e.ActionId == ImeAction.Next) || (e.ActionId == ImeAction.ImeNull)) {
				if (editText.Equals (_searchFrom)) {
					if (_searchTo.Text.Length == 0) {
						//Focus _searchTo
						//HideKeyboard (Activity, editText.WindowToken);
						//-ShowKeyboard (Activity, _searchTo);
					} else {
						//-HideKeyboards ();
						await BeginSearch ();
					}
				} else if (editText.Equals (_searchTo)) {
					if (editText.Text.Length == 0) {
						//-HideKeyboard (Activity, editText.WindowToken);
					} else {
						//-HideKeyboards ();
						await BeginSearch ();
					}
				}
			}
		}



		void HandleTestClick (object sender, EventArgs e) {
			MainActivity.NavigateToPage (1);
			//MainActivity.StartActivity (typeof(DealsActivity));
		
		}

		private void HandleSearchFromButtonClick (object sender, EventArgs e) {
			var searchHistory = new Intent(MainActivity, typeof(SearchHistoryActivity));
			StartActivityForResult(searchHistory, 1);
			MainActivity.OverridePendingTransition(Resource.Animation.slide_enter, Resource.Animation.slide_exit);
		}

		private void HandleSearchToButtonClick (object sender, EventArgs e) {
			var searchHistory = new Intent(MainActivity, typeof(SearchHistoryActivity));
			StartActivityForResult(searchHistory, 2);
			MainActivity.OverridePendingTransition(Resource.Animation.slide_enter, Resource.Animation.slide_exit);
		}

		public override void OnActivityResult (int requestCode, int resultCode, Intent data) {
			base.OnActivityResult (requestCode, resultCode, data);

			if (resultCode == (int)Result.Ok) {
				if (requestCode == 1) {
					//From
					StateManager.Instance.Departure = SearchHistory.Load().Locations[Convert.ToInt32(data.GetStringExtra("result"))];
					_searchFrom.Text = StateManager.Instance.Departure.Label;
					//_searchTo.RequestFocus ();
				} else {
					//To
					StateManager.Instance.Destination = SearchHistory.Load().Locations[Convert.ToInt32(data.GetStringExtra("result"))];
					_searchTo.Text = StateManager.Instance.Destination.Label;
					//_searchFrom.RequestFocus ();
				}
			}
		}

		private void HideKeyboard(Context context, IBinder windowToken) {
			var mgr = (InputMethodManager) context.GetSystemService (Context.InputMethodService);
			mgr.HideSoftInputFromWindow (windowToken, 0);

			//InputMethodManager mgr = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
			//mgr.hideSoftInputFromWindow(windowToken, 0);
		}


		public static void ShowKeyboard(Context context, View pView) {
			pView.RequestFocus();

			var mgr = (InputMethodManager) context.GetSystemService (Context.InputMethodService);
			mgr.ShowSoftInput(pView, ShowFlags.Forced);
			mgr.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
		}

		/*
		public static void HideKeyboard(View pView, Context context) {
			InputMethodManager inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager;
			inputMethodManager.HideSoftInputFromWindow(pView.WindowToken, HideSoftInputFlags.None);
		}
		*/


		private async Task<bool> ShowFromActionSheet(LocationBase[] locations) {
			Func<bool> function = new Func<bool>(() => ShowFromActionSheetJob(locations));
			return await Task.Run<bool>(function);
		}

		private bool ShowFromActionSheetJob(LocationBase[] locations) {
			_locations = locations;

			using (var alert = new AlertDialog.Builder (MainActivity)) {
				alert.SetTitle ("(removed the actual content).");
				alert.SetItems (locations.Select (s => s.Label).ToArray (), DialogFromListClicked);

				_dialog = alert.Create ();
				_dialog.Show ();
			}

			return true;
		}

		private async Task<bool> ShowToActionSheet (LocationBase[] locations) {
			Func<bool> function = new Func<bool>(() => ShowToActionSheetJob(locations));
			return await Task.Run<bool>(function);
		}

		private void ShowActionSheet(LocationBase[] locations, string target) {
			_locations = locations;

			if (Activity != null) {
				Activity.RunOnUiThread (() => {
					using (var alert = new AlertDialog.Builder (MainActivity)) {
						alert.SetTitle (String.Format("(removed the actual content) {0}.", target));
						alert.SetItems (locations.Select (s => s.Label).ToArray (), DialogToListClicked);

						_dialog = alert.Create ();
						_dialog.Show ();
					}
				});
			}
		}

		private bool ShowToActionSheetJob(LocationBase[] locations) {
			_locations = locations;


			using (var alert = new AlertDialog.Builder (MainActivity)) {
				alert.SetTitle ("(removed the actual content)");
				alert.SetItems (locations.Select (s => s.Label).ToArray (), DialogToListClicked);

				_dialog = alert.Create ();
				_dialog.Show ();
			}

			return true;
		}

		private void ShowFromActionSheetOLD (LocationBase[] locations) {
			_locations = locations;

			using (var alert = new AlertDialog.Builder (MainActivity)) {
				alert.SetTitle ("(removed the actual content)");
				alert.SetItems (locations.Select (s => s.Label).ToArray (), DialogFromListClicked);

				_dialog = alert.Create ();
				_dialog.Show ();

			}


			/*
			var actionSheet = new UIActionSheet ("Kies locatie van vertrek.");

			foreach (var location in locations) {
				actionSheet.AddButton (location.Label);
			}

			actionSheet.Clicked += (object sender, UIButtonEventArgs e) => {
				var location = locations [e.ButtonIndex];
				StateManager.Instance.Departure = location;
				_fromField.Text = location.Label;

				PerformSearch (actionSheet, null);
			};

			actionSheet.ShowInView (this.View);
			*/
		}

		private void ShowToActionSheetOLD (LocationBase[] locations) {
			_locations = locations;

			using (var alert = new AlertDialog.Builder (MainActivity)) {
				alert.SetTitle ("(removed the actual content)");
				alert.SetItems (locations.Select (s => s.Label).ToArray (), DialogToListClicked);

				_dialog = alert.Create ();
				_dialog.Show ();
			}
		}

		private void DialogFromListClicked (object sender, DialogClickEventArgs e) {
			Console.WriteLine ("DialogFromListClicked");
			_dialog.Dismiss ();

			var location = _locations [e.Which];
			StateManager.Instance.Departure = location;
			_searchFrom.Text = location.Label;
			HideKeyboard(Activity, _searchFrom.WindowToken);

			HandleSearchButtonClick (_dialog, null);
		}

		private void DialogToListClicked (object sender, DialogClickEventArgs e) {
			Console.WriteLine ("DialogToListClicked");
			_dialog.Dismiss ();

			var location = _locations [e.Which];
			StateManager.Instance.Destination = location;
			_searchTo.Text = location.Label;
			HideKeyboard(Activity, _searchTo.WindowToken);

			HandleSearchButtonClick (_dialog, null);
		}

		private async Task<bool> BeginSearch() {
			Console.WriteLine ("BeginSearch()");

			MainActivity.LocClient.Connect ();
			await PerformSearch ();

			return true;
		}


		private async void HandleSearchButtonClick (object sender, EventArgs e) {
			if (MainActivity.Manager.ConnectionValidator.IsConnected == false) {
				MainActivity.ShowAlert ("", "Er is geen actieve internetverbinding beschikbaar", "OK");
			} else if (MainActivity.IsGooglePlayServicesInstalled() == false) {
				MainActivity.ShowAlert ("Geen Google Play Services", "Deze app heeft Google Play services nodig. Google Play services is gratis te downloaden van de App Store", "OK");
			} else {
				DisableAllElements ();
				MainActivity.LocClient.Connect ();

				_progressSearch.Visibility = ViewStates.Visible;
				_searchButton.Text = "Zoeken ...";

				await PerformSearch ();

				_searchButton.Text = "Toon reisinfo";
				_progressSearch.Visibility = ViewStates.Invisible;
				EnableAllElements ();
			}
		}

		private async Task<bool> PerformSearch() {
			Console.WriteLine ("PerformSearch()");

			Func<bool> function = new Func<bool>(() => PerformSearchJob());
			return await Task.Run<bool>(function);
		}

		private void DisableAllElements() {
			_searchButton.Enabled = false;
			DisableElements ();
		}

		private void EnableAllElements() {
			_searchButton.Enabled = true;
			EnableElements ();
		}

		private void DisableElements() {
			_searchFrom.Enabled = false;
			_searchTo.Enabled = false;
		}

		private void EnableElements() {
			_searchFrom.Enabled = true;
			_searchTo.Enabled = true;
		}


		private bool PerformSearchJob() {
			Console.WriteLine ("PerformSearchJob" + DateTime.Now.ToString ());

			var stateManager = StateManager.Instance;

			if (_searchTo.Text.Trim ().Length == 0) {
				MainActivity.ShowAlert ("", "Voer bestemming in.", "OK");
				return true;
			}

			// (removed the actual content)
			var accessToken = stateManager.AccessToken ?? null;
			var client = new SomeClient ();
			if (client.Authenticated == false) {
				var success = client.AuthenticateAsync ().Result;

				if (success == false) {
					MainActivity.ShowAlert ("Error", "(removed the actual content)", "OK");
					return true;
				}
			}

			// (removed the actual content)
			// (removed the actual content)
			// (removed the actual content)

			LocationBase[] fromLocations = null;

			if (stateManager.Departure is CurrentLocation) {
				try {

					//if (_fromField.Text.Equals (stateManager.Departure.Label)) {
					if (_searchFrom.Text == "") {
						if (MainActivity.LocationCurrent == null) {
							throw new Exception ("no current location");
						}

						var latitude = MainActivity.LocationCurrent.Latitude;
						var longitude = MainActivity.LocationCurrent.Longitude;
						var location =  client.LocationAsync (latitude, longitude).Result;

						fromLocations = new LocationBase[]{ location };
					} else {
						fromLocations = client.SearchAsync (_searchFrom.Text).Result;
					}
				} catch (Exception ex) {
					throw(ex);

					MainActivity.ShowAlert ("Error", ex.Message, "OK");
					return true;
				}

				if (fromLocations == null) {
					MainActivity.ShowAlert ("", "(removed the actual content)", "OK");
					return true;
				} 
			}

			LocationBase[] toLocations = null;

			if (stateManager.Destination == null ||
				stateManager.Destination.Label.Equals (_searchTo.Text) == false) {
				stateManager.Destination = null;

				try {
					toLocations = client.SearchAsync (_searchTo.Text).Result;
				} catch (Exception ex) {
					MainActivity.ShowAlert ("Error", ex.Message, "OK");
					return true;
				}

				if (toLocations == null || toLocations.Length == 0) {
					MainActivity.ShowAlert ("", "(removed the actual content)", "OK");
					return true;
				}
			}

			if (fromLocations != null) {
				if (fromLocations.Length > 1) {
					//MainActivity.ShowAlert ("TODO", "ShowFromActionSheet.", "OK");
					ShowActionSheet (fromLocations, "vertrek");
					return true;
				} else if (fromLocations.Length == 1) {
					stateManager.Departure = fromLocations [0];
				}
			}

			if (stateManager.Destination == null) {
				if (toLocations.Length > 1) {
					//MainActivity.ShowAlert ("TODO", "ShowFromActionSheet.", "OK");
					ShowActionSheet (toLocations, "(removed the actual content)");
					return true;
				} else if (toLocations.Length == 1) {
					stateManager.Destination = toLocations [0];
				}
			}

			if (stateManager.Departure != null && stateManager.Destination != null) {
				var fromHref = stateManager.Departure.Link.AbsoluteUri;
				var toHref = stateManager.Destination.Link.AbsoluteUri;

				if (fromHref.Equals (toHref)) {
					MainActivity.ShowAlert ("", "(removed the actual content)", "OK");
					return true;
				}

				var history = SearchHistory.Load ();
				history.InsertLocation (stateManager.Destination);

				if ((stateManager.Departure is CurrentLocation) == false) {
					history.InsertLocation (stateManager.Departure);
				}

				history.Store ();

				try {
					stateManager.Trips = client.SearchAsync (fromHref, toHref).Result;
					HideKeyboard(Activity, _searchFrom.WindowToken);
					HideKeyboard(Activity, _searchTo.WindowToken);
					MainActivity.NavigateToPage(1);


					//MainActivity.ShowAlert ("TODO", "ShowLeftViewController.", "OK");

					//_parentViewController.TransitioningEnabled = true;
					//_parentViewController.ShowLeftViewController (null, null);
				} catch (Exception ex) {
					MainActivity.ShowAlert ("ERROR", ex.Message, "OK");
				}


			} else {
				// TODO: vertreklocatie / bestemming niet gevonden
				MainActivity.ShowAlert ("", "(removed the actual content)", "OK");
			}

			return true;
		}
	}
}
[/code]

See attached screenshot for details
Comment 1 djnonsens 2014-08-09 08:30:01 UTC
Created attachment 7641 [details]
This image shows the problem
Comment 2 djnonsens 2014-08-09 08:42:23 UTC
Created attachment 7642 [details]
This image shows the same problem with collapsed error message
Comment 3 djnonsens 2014-08-09 08:53:35 UTC
I just downgraded to xamarin.studio 5.1.4 (build 0), where this problem does not occur. I am using Xamarin.Android version: 4.14.0 (Indie Edition), and was using the same version in Xamarin Studio 5.2 (build 386)
Comment 4 Ram Chandra 2014-08-11 07:22:09 UTC
I tried to reproduce this issue but I am unable to reproduce this issue.

Steps I followed:

1. Create an "Android Application" on XS
2. Add the following code on MainView
    
     protected override void OnResume () {
            Console.WriteLine ("SearchFragment OnResume");
            //_searchButton.Touch += HandleSearchButtonTouch;
            //_btnButton.Click += HandleClick;
            base.OnResume ();
        }

        void HandleClick (object sender, EventArgs e) {
             Console.WriteLine("This is button Handler");
        }

3. Debug the project.

When I debug the project I observed that I am not getting any NRE exception and app is running without any error/exception.

Screencast: http://www.screencast.com/t/xKYTOXMtPHX

Could you please attached the IDE logs and sample project? So, that we can reproduce this issue at our end.

You can get IDE logs from here: Xamarin Studio=> Open Log directory => Ide.(date).log (attach latest log).

Environment  Info:

=== Xamarin Studio ===

Version 5.2 (build 386)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 3.8.0 ((no/9ffca33)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000002

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 7.4.0.96 (Trial Edition)
Hash: a124188
Branch: 
Build date: 2014-08-07 14:57:55-0400

=== Xamarin.Mac ===

Version: 1.8.0.8

=== Xamarin.Android ===

Version: 4.14.0 (Trial Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		1.6   (API level 4)
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

=== Build Information ===

Release ID: 502000386
Git revision: e6a54dee5376e6e7a2d9982695b060fddc09e65d
Build date: 2014-08-04 14:03:28-04
Xamarin addins: 2b5a5c26ac2ee74c6e91a8d24ef44d0ca9cb74d0

=== Operating System ===

Mac OS X 10.9.3
Darwin Jatin66s-iMac.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 5 djnonsens 2014-09-05 05:32:06 UTC
I'm sorry for my late response, basically forgot about it, until today with the release of version 5.3. 

I actually started screen recording, but was not able to reproduce this problem in 5.3, so I'm not sure what happened, but for me this case is closed.

Thank you for investigating.
Comment 6 Shruti 2015-01-20 04:39:19 UTC
AS per comment 5, closing this issue.