ADAL - AcquireTokenHandlerBase.cs: System.ArgumentNullException: String reference not set to an instance of a String
<p>I used ADAL with ADFS for authenticating web api calls within Xamarin and is experiencing an issue when repeating the authentication process, it appears to be having issue with getting token from the in-memory cache.</p>

<p>Interestingly, I have another demo app which does the same thing and doesn't have the same issue...</p>

<p>The code used is as below, if anyone can shield some lights on how to debug it further it will be much appreciated.</p>

<pre><code>try
{
  AuthenticationContext ac = new AuthenticationContext(authority, false);

  try
  {
     ar = ac.AcquireTokenSilentAsync(resourceURI, clientID).Result;
  }
  catch (AggregateException exc)
  {
      //do nothing?
  }

  if (ar == null)
  {
     ar = await ac.AcquireTokenAsync(resourceURI, clientID, new Uri(clientReturnURI), parent);
  }
  **catch (Exception ex)**  //always been hit
  {
</code></pre>

<blockquote>
  <p>2016-08-14 22:54:46.075 TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46
  AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: Looking up
  cache for a token... 2016-08-14 22:54:46.076
  TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46 AM:
  c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: An item matching
  the requested resource was found in the cache 2016-08-14 22:54:46.076
  TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46 AM:
  c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: 29.0067555833333
  minutes left until token in cache expires 2016-08-14 22:54:46.077
  TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46 AM:
  c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: A matching item
  (access token or refresh token or both) was found in the cache
  2016-08-14 22:54:46.082 TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46
  AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - AcquireTokenHandlerBase.cs:
  System.ArgumentNullException: String reference not set to an instance
  of a String. Parameter name: s   at System.Text.Encoding.GetBytes
  (System.String s) [0x00006] in
  /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/text/encoding.cs:1083
  at
  Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.CreateSha256Hash
  (System.String input) [0x0000c] in :0    at
  Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.LogReturnedToken
  (Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
  result) [0x00067] in :0    at
  Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.PostRunAsync
  (Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
  result) [0x</p>
</blockquote>