Bug 30933 - System.NullReferenceException when calling HttpListener.start() on Android 5.0 (API 21)
Summary: System.NullReferenceException when calling HttpListener.start() on Android 5....
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 5.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2015-06-09 05:10 UTC by Adam Hartley [MSFT]
Modified: 2015-08-10 14:25 UTC (History)
4 users (show)

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


Attachments
Sample project (25.06 KB, application/zip)
2015-06-09 05:10 UTC, Adam Hartley [MSFT]
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:
RESOLVED NOT_REPRODUCIBLE

Description Adam Hartley [MSFT] 2015-06-09 05:10:25 UTC
Created attachment 11530 [details]
Sample project

## Overview

A System.NullReferenceException occurs when calling HttpListener.start() on Android 5.0 (API 21).

This only appears to happen on API 21, lower and higher versions appear to be unaffected.

## Steps to reproduce

1. Download attached sample
2. Run on a device / emulator with Android 5.0.x (API 21)
3. Observe crash at listener.start()

## Expected result

No exception

## Actual Result

Exception thrown at listener.start()


Exception:

System.NullReferenceException: Object reference not set to an instance of an object

Exception:

System.NullReferenceException: Object reference not set to an instance of an object

System.NullReferenceException: Object reference not set to an instance of an object
06-08 13:58:15.896 D/Mono    (20226): DllImport attempting to load: '/system/lib/liblog.so'.
  at System.Net.Sockets.Socket.AcceptAsync (System.Net.Sockets.SocketAsyncEventArgs e) [0x0011b] in <filename unknown>:0 
  at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x0008c] in <filename unknown>:0 
06-08 13:58:15.896 D/Mono    (20226): DllImport loaded library '/system/lib/liblog.so'.
  at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x000be] in <filename unknown>:0 
06-08 13:58:15.896 D/Mono    (20226): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
06-08 13:58:15.896 D/Mono    (20226): Searching for '__android_log_print'.
  at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00064] in <filename unknown>:0 
06-08 13:58:15.896 D/Mono    (20226): Probing '__android_log_print'.
06-08 13:58:15.896 D/Mono    (20226): Found as '__android_log_print'.
06-08 13:58:15.897 I/mono-stdout(20226): System.NullReferenceException: Object reference not set to an instance of an object
  at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00030] in <filename unknown>:0 
06-08 13:58:15.901 I/mono-stdout(20226):   at System.Net.Sockets.Socket.AcceptAsync (System.Net.Sockets.SocketAsyncEventArgs e) [0x0011b] in <filename unknown>:0 
06-08 13:58:15.903 I/mono-stdout(20226):   at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x0008c] in <filename unknown>:0 
06-08 13:58:15.905 I/mono-stdout(20226):   at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x000be] in <filename unknown>:0 
06-08 13:58:15.907 I/mono-stdout(20226):   at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00064] in <filename unknown>:0 
06-08 13:58:15.910 I/mono-stdout(20226):   at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00030] in <filename unknown>:0 
Exception:

System.NullReferenceException: Object reference not set to an instance of an object

06-08 13:58:16.482 D/Mono    (20226): DllImport attempting to load: '/system/lib/liblog.so'.
06-08 13:58:16.482 D/Mono    (20226): DllImport loaded library '/system/lib/liblog.so'.
06-08 13:58:16.483 D/Mono    (20226): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
06-08 13:58:16.483 D/Mono    (20226): Searching for '__android_log_print'.
06-08 13:58:16.483 D/Mono    (20226): Probing '__android_log_print'.
06-08 13:58:16.483 D/Mono    (20226): Found as '__android_log_print'.
06-08 13:58:16.521 I/MonoDroid(20226): UNHANDLED EXCEPTION:
06-08 13:58:16.522 I/MonoDroid(20226): System.NullReferenceException: Object reference not set to an instance of an object
06-08 13:58:16.522 I/MonoDroid(20226):   at System.Net.Sockets.Socket.AcceptAsync (System.Net.Sockets.SocketAsyncEventArgs e) [0x0011b] in <filename unknown>:0 
06-08 13:58:16.522 I/MonoDroid(20226):   at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x0008c] in <filename unknown>:0 
06-08 13:58:16.522 I/MonoDroid(20226):   at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x000be] in <filename unknown>:0 
06-08 13:58:16.522 I/MonoDroid(20226):   at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00064] in <filename unknown>:0 
06-08 13:58:16.522 I/MonoDroid(20226):   at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00030] in <filename unknown>:0 
06-08 13:58:16.546 W/art     (20226): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
06-08 13:58:16.549 D/AndroidRuntime(20226): Shutting down VM
An unhandled exception occured.

06-08 13:58:17.097 E/AndroidRuntime(20226): FATAL EXCEPTION: main
06-08 13:58:17.097 E/AndroidRuntime(20226): Process: App3.App3, PID: 20226
06-08 13:58:17.097 E/AndroidRuntime(20226): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
06-08 13:58:17.097 E/AndroidRuntime(20226): Caused by: java.lang.reflect.InvocationTargetException
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at java.lang.reflect.Method.invoke(Native Method)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at java.lang.reflect.Method.invoke(Method.java:372)
06-08 13:58:17.097 E/AndroidRuntime(20226): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an i06-08 13:58:17.097 E/AndroidRuntime(20226): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	... 1 more
06-08 13:58:17.097 E/AndroidRuntime(20226): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
06-08 13:58:17.097 E/AndroidRuntime(20226):   at System.Net.Sockets.Socket.AcceptAsync (System.Net.Sockets.SocketAsyncEventArgs e) [0x0011b] in <filename unknown>:0 
06-08 13:58:17.097 E/AndroidRuntime(20226):   at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x0008c] in <filename unknown>:0 
06-08 13:58:17.097 E/AndroidRuntime(20226):   at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x000be] in <filename unknown>:0 
06-08 13:58:17.097 E/AndroidRuntime(20226):   at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00064] in <filename unknown>:0 
06-08 13:58:17.097 E/AndroidRuntime(20226):   at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00030] in <filename unknown>:0 
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at md5db1d84f0b2adc09d2fa403805cf2e153.MainActivity.n_onCreate(Native Method)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at md5db1d84f0b2adc09d2fa403805cf2e153.MainActivity.onCreate(MainActivity.java:29)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.Activity.performCreate(Activity.java:5933)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.ActivityThread.access$800(ActivityThread.java:144)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.os.Handler.dispatchMessage(Handler.java:102)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.os.Looper.loop(Looper.java:135)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	at android.app.ActivityThread.main(ActivityThread.java:5221)
06-08 13:58:17.097 E/AndroidRuntime(20226): 	... 4 more
06-08 13:58:17.147 I/Process (20226): Sending signal. PID: 20226 SIG: 9
Comment 1 Rajneesh Kumar 2015-06-09 07:09:21 UTC
I tried to reproduce this issue but not able to reproduce. To reproduce this issue I have followed the steps and instruction provides in bug description.

1. Open attached sample in XS.
2. Run on a device / emulator with Android 5.0.x (API 21)
3. Observe that it deploy successfully, without any exception.

Screencast: http://www.screencast.com/t/5a7xt5gG

Could you please let me know that what steps I am missing/wrong to reproduce this issue. That would be very helpful to reproduce this issue a our end.

Thanks..!

Ide Logs: https://gist.github.com/Rajneesh360Logica/e15cdbf12fcc3047a779
Build output: https://gist.github.com/Rajneesh360Logica/9dfecd0a7509a59a4819
Application Output: https://gist.github.com/Rajneesh360Logica/4ffafc5a22c009a28de9

Environment Info:

=== Xamarin Studio ===

Version 5.9.4 (build 4)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 4.0.2 ((detached/198235d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020004

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.10.2.16 (Business Edition)
Hash: b2ebbc0
Branch: master
Build date: 2015-06-06 01:13:21-0400

=== Xamarin.Android ===

Version: 5.1.4.8 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		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)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.16 (Business Edition)

=== Build Information ===

Release ID: 509040004
Git revision: 0c8e73f6b66e066a642724a8241a0998b6329180
Build date: 2015-06-08 11:30:54-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Adam Hartley [MSFT] 2015-06-11 04:38:15 UTC
This actually appears to only be happening on a device, not in the emulator as I first suggested.

It was tested on a 5.0.x Nexus 7 and was able to be replicated.

=== Xamarin Studio ===

Version 5.9.3 (build 1)
Installation UUID: 9932d50e-3095-4eb8-a4d2-d3b271c86a02
Runtime:
	Mono 4.0.1 ((detached/ed1d3ec)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010044

=== Apple Developer Tools ===

Xcode 6.3.2 (7718)
Build 6D2105

=== Xamarin.iOS ===

Version: 8.10.1.64 (Business Edition)
Hash: e6ebd18
Branch: master
Build date: 2015-05-21 21:55:09-0400

=== Xamarin.Android ===

Version: 5.1.3.1 (Business Edition)
Android SDK: /Users/Adam/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.1.64 (Business Edition)

=== Build Information ===

Release ID: 509030001
Git revision: 5a524e1726ed103fdd4fe37e0356f2b35466ce9d
Build date: 2015-06-02 16:35:08-04
Xamarin addins: 51957cfbd06be911b212671ad05c2c6221ac90f9

=== Operating System ===

Mac OS X 10.10.3
Darwin Adams-Retina-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 3 Rajneesh Kumar 2015-08-05 14:13:13 UTC
Hi Adam,
 I have again checked this issue with the device Nexus 7 (Version 5.1.1) and Nexus 6 (Version 5.0) and I am not able to reproduce this at my end. I am able to deploy the attached test sample successfully, on both device.

Could you please let me know that what steps I am still missing to reproduce this issue. Also please attach your device logs, that will be very helpful for developer to investigate this issue.

Thanks..!
Comment 4 Adam Hartley [MSFT] 2015-08-10 10:25:07 UTC
Hi Rajneesh,

Interestingly I tried the sample again on multiple devices and API levels (via Test Cloud), but was also unable to reproduce to original issue. Possibly this has been resolved since initially filed, so I will mark it as resolved.
Comment 5 Rajneesh Kumar 2015-08-10 14:25:49 UTC
@Adam Thanks a lot for the clarification of issue, and updating it here.

Thanks..!