title: Xamarin.iOS Operation is not supported on this platform Exception at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod
body: <p>I'm working on a cross-platform project with Xamarin.Forms. In my project, I'm using an API to login by a username and password. When I try to login on Android and UWP platorms, it works perfectly. But when I want to login in my iOS project, It throws an exception that says: </p>
  
  <blockquote>
    <p>System.PlatformNotSupportedException: Operation is not supported on
    this platform.</p>
  </blockquote>
  
  <p>The Exception is thrown on this line of my code:</p>
  
  <pre><code>HttpContent content = new FormUrlEncodedContent(keyValuePairs);
  HttpResponseMessage response = await httpClient.PostAsync("token", content);
  </code></pre>
  
  <p>Here is the full StackTrace:</p>
  
  <blockquote>
    <p>at System.Reflection.Emit.DynamicMethod..ctor (System.String name,
    System.Type returnType, System.Type[] parameterTypes, System.Type
    owner, System.Boolean skipVisibility) [0x00006] in
    /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/src/Xamarin.iOS/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.notsupported.cs:62</p>
    
    <p>at
    Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod
    (System.String name, System.Type returnType, System.Type[]
    parameterTypes, System.Type owner) [0x00000] in
    /_/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs:45  </p>
    
    <p>at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T]
    (System.Type type) [0x00000] in
    /_/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs:244</p>
    
    <p>at
    Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator
    (System.Type createdType) [0x00000] in
    /_/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:780   </p>
    
    <p>at
    Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract
    (Newtonsoft.Json.Serialization.JsonContract contract) [0x0008b] in
    /_/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:813   </p>
    
    <p>at
    Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract
    (System.Type objectType) [0x00007] in
    /_/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:340   </p>
    
    <p>at
    Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract
    (System.Type objectType) [0x0010f] in
    /_/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:1249  </p>
    
    <p>at
    System.Collections.Concurrent.ConcurrentDictionary<code>2[TKey,TValue].GetOrAdd
    (TKey key, System.Func</code>2[T,TResult] valueFactory) [0x00034] in
    /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/src/Xamarin.iOS/external/corefx/src/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs:1003</p>
    
    <p>at Newtonsoft.Json.Utilities.ThreadSafeStore`2[TKey,TValue].Get (TKey
    key) [0x00000] in
    /_/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs:64  </p>
    
    <p>at
    Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract
    (System.Type type) [0x0000b] in
    /_/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:198   </p>
    
    <p>at
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe
    (System.Type type) [0x0000b] in
    /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:133</p>
    
    <p>at
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize
    (Newtonsoft.Json.JsonReader reader, System.Type objectType,
    System.Boolean checkAdditionalContent) [0x0000e] in
    /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:143</p>
    
    <p>at Newtonsoft.Json.JsonSerializer.DeserializeInternal
    (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00046]
    in /_/Src/Newtonsoft.Json/JsonSerializer.cs:907    </p>
    
    <p>at
    Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader
    reader, System.Type objectType) [0x00000] in
    /_/Src/Newtonsoft.Json/JsonSerializer.cs:886   </p>
    
    <p>at
    Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value,
    System.Type type, Newtonsoft.Json.JsonSerializerSettings settings)
    [0x0002d] in /_/Src/Newtonsoft.Json/JsonConvert.cs:830   </p>
    
    <p>at
    Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value,
    Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in
    /_/Src/Newtonsoft.Json/JsonConvert.cs:786   </p>
    
    <p>at
    Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value)
    [0x00000] in /_/Src/Newtonsoft.Json/JsonConvert.cs:719   </p>
    
    <p>at
    Restaurant.Core.DataServices.LoginDataService+d__0.MoveNext ()
    [0x00222] in
    C:\Projects\Restaurant\Restaurant\Restaurant.Core\DataServices\LoginDataService.cs:44</p>
    
    <p>--- End of stack trace from previous location where exception was thrown ---<br>
    at
    Restaurant.Core.ViewModels.Login.LoginViewModel+&lt;b__13_0>d.MoveNext
    () [0x00058] in
    C:\Projects\Restaurant\Restaurant\Restaurant.Core\ViewModels\Login\LoginViewModel.cs:78</p>
    
    <p>--- End of stack trace from previous location where exception was thrown ---<br>
    at
    Restaurant.Core.Helpers.ExceptionHandler+d__3.MoveNext
    () [0x000f6] in
    C:\Projects\Restaurant\Restaurant\Restaurant.Core\Helpers\ExceptionHandler.cs:38</p>
  </blockquote>
  
  <p>I Googled it and finally found that Xamarin.iOS has <a href="https://docs.microsoft.com/en-us/xamarin/ios/internals/limitations#no-dynamic-code-generation" rel="nofollow noreferrer">some limitations</a>. The System.Reflection.Emit is not available in Xamarin.iOS.</p>
  
  <p>I guess something is wrong with Newtonsoft.Json or maybe with Xamarin itself, But I don't know how to solve the problem.</p>