Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unity problem with HTTPS

Another problem I faced with while development of Unity plugin is Exception while HTTP request from the iOS platform. It produces such stacktrace:

ExecutionEngineException: Attempting to JIT compile method 'System.Reflection.MonoProperty:GetterAdapterFrame<Mono.Security.Protocol.Tls.HttpsClientStream, bool> (System.Reflection.MonoProperty/Getter`2<Mono.Security.Protocol.Tls.HttpsClientStream, bool>,object)' while running with --aot-only.

  at System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnection.Write (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.String& err_msg) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnectionStream.WriteHeaders () [0x00000] in <filename unknown>:0 
  at System.Net.WebConnectionStream.SetHeaders (System.Byte[] buffer) [0x00000] in <filename unknown>:0 
  at System.Net.HttpWebRequest.SendRequestHeaders (Boolean propagate_error) [0x00000] in <filename unknown>:0 
Rethrow as AIServiceException: Attempting to JIT compile method 'System.Reflection.MonoProperty:GetterAdapterFrame<Mono.Security.Protocol.Tls.HttpsClientStream, bool> (System.Reflection.MonoProperty/Getter`2<Mono.Security.Protocol.Tls.HttpsClientStream, bool>,object)' while running with --aot-only.

System.Net.WebConnection.Write method uses some reflection methods. Quick search led me to this answer. But the highlighted answer suggests very complicated solution. So, the another solution, that I found was to select "Api Compatibility Level"=".NET 2.0 Subset" in the Player Settings.

@hscheidl

This comment has been minimized.

Copy link

@hscheidl hscheidl commented Sep 11, 2015

I had this problem in an android build with Unity 5.1.3. It was due to stripping.
Preserving class System.Reflection.MonoProperty fixed the problem

Here is my link.xml file:

<linker>
    <assembly fullname="System">
        <namespace fullname="System.ComponentModel" preserve="all"/>
        <namespace fullname="System.Net" preserve="all"/>
        <namespace fullname="System.Net.Configuration" preserve="all"/>
        <namespace fullname="System.Threading" preserve="all"/>
        <namespace fullname="System.Net.Sockets" preserve="all"/>
        <namespace fullname="System.IO" preserve="all"/>
        <namespace fullname="System.Text" preserve="all"/>
        <namespace fullname="System.Collections" preserve="all"/>
        <namespace fullname="System.Collections.Generic" preserve="all"/>
        <type fullname="System.Net.WebRequest" preserve="all"/>
        <namespace fullname="System.Diagnostics" preserve="all"/>
        <namespace fullname="System.Diagnostics.DiagnosticsConfigurationHandler" preserve="all"/>
        <namespace fullname="System" preserve="all"/>
    </assembly>

    <assembly fullname="mscorlib">
        <namespace fullname="System.Security.Cryptography" preserve="all"/>
        <type fullname="System.Net.WebResponse" preserve="all" />
        <type fullname="System.Net.HttpWebResponse" preserve="all" />
        <type fullname="System.Reflection.MonoProperty" preserve="all" />
    </assembly>

    <assembly fullname="System.Configuration">
        <namespace fullname="System.Configuration.ExeConfigurationHost" preserve="all"/>
        <namespace fullname="System.Configuration" preserve="all"/>
    </assembly>

    <assembly fullname="Mono.Security">
        <namespace fullname="Mono.Security.Protocol.Tls" preserve="all"/>
        <namespace fullname="Mono.Security.X509" preserve="all"/>
    </assembly>
</linker>
@xVir

This comment has been minimized.

Copy link
Owner Author

@xVir xVir commented Oct 12, 2015

@hscheidl Great! Thanks for the advise! I have faced with the problem before Unity 5.1, and your solution seems more correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment