Bug 13998 - Exception when consuming HTTPS endpoint with Linking Behaviour set to Link Framework SDKs Only
Summary: Exception when consuming HTTPS endpoint with Linking Behaviour set to Link Fr...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: mmp ()
Version: 1.4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2013-08-15 08:18 UTC by Malcolm
Modified: 2014-01-14 00:19 UTC (History)
3 users (show)

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

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 FIXED

Description Malcolm 2013-08-15 08:18:55 UTC
When including the Mono runtime and enabling linking (Link Behaviour = Link Framework SDKs Only) an attempt to read data from an HTTPS endpoint with an improper certificate (self signed for example) throws an exception:

System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.Exception: The authentication or decryption has failed. ---> System.Exception: Object reference not set to an instance of an object
  at Mono.Security.Protocol.Tls.CipherSuite.createEncryptionCipher () [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.CipherSuite.InitializeCipher () [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslClientStream.OnNegotiateHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at System.Threading.Tasks.TaskFactory`1[System.Net.WebResponse].InnerInvoke (System.Threading.Tasks.TaskCompletionSource`1 tcs, System.Func`2 endMethod, IAsyncResult l) [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Threading.Tasks/TaskFactory_T.cs:473
  at --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.WebResponse].GetResult () [0x00011] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Runtime.CompilerServices/ConfiguredTaskAwaitable_T.cs:58
  at System.Net.Http.HttpClientHandler+<SendAsync>c__asyncC.MoveNext () [0x00000] in <filename unknown>:0
  at --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult () [0x00011] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Runtime.CompilerServices/ConfiguredTaskAwaitable_T.cs:58
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async5.MoveNext () [0x00000] in <filename unknown>:0
  at --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
  at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00033] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.1/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59
  at CertRnD.MainWindowController+<DoStuff>c__async0.MoveNext () [0x000b8] in /Users/malcolmvs/Projects/CertRnD/CertRnD/MainWindowController.cs:70

This seems to be related to Aes.Create () which uses reflection to create an instance of AesCryptoServiceProvider.

Obviously reflection makes linking difficult.

The current way around this is to include the following in the Advanced Mono Bundling Options - Extra Arguments (Mac OS X Packaging / Advanced):

--linkskip=System.Core
Comment 1 kevinknoop 2013-09-26 04:46:12 UTC
Any update on this?
Comment 2 Sebastien Pouliot 2013-11-04 17:17:23 UTC
Fixed in master 79d1f5a637a3f1615f807160d88e352e307c95d3

QA: mmp regression test added in e63346606074ab34cb4e93b2d72d471dd72d2842


Until a fix is released the workaround is to either use:

* --linkskip=System.Core

or

* Create an instance of AesCryptoServiceProvider somewhere in your code so that the linker won't remove it.
Comment 3 Gerry 2014-01-05 01:27:03 UTC
Ironically am seeing this exact same bug in Xamarin.Android alpha channel build Xamarin.Android 4.11.0, Mono 3.2.5

Do I need to bug this or are you aware of it?
Comment 4 Sebastien Pouliot 2014-01-13 21:42:04 UTC
Gerry, the exception from #12381 (comment #18) is not identical to this one, i.e. there's no "Object
reference not set to an instance of an object" indicating a NullReferenceException occurred,

@Skall comment on http://forums.xamarin.com/discussion/comment/35230/#Comment_35230 is likely the right solution. If not please open a new Android-related issue.
Comment 5 Gerry 2014-01-14 00:19:30 UTC
Sebastien--ok, my bad on #12381.  However, I can confirm that I was seeing bug #13998 on Xamarin.Android 4.11/Mono 3.2.5 and by adding the fix of 
System.Security.Cryptography.AesCryptoServiceProvider b = new System.Security.Cryptography.AesCryptoServiceProvider(); 

to my code it worked.

- Gerry