Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Robert-Castle · Jul 20, 2012 at 08:59 PM · c#iosnetworkingreflectionjit

HttpWebResponse and JIT on iOS

I am having JIT compiler issues with the following code on iOS. The code works in the editor (on a Mac), but not on an iOS device. I am using .NET 2.0, iOS 5.1, No stripping, and slow and safe calls. I have not installed any additional libraries.

 using UnityEngine;
 using System.Collections;
 using System.IO;
 using System.Security;
 using System.Security.Cryptography;
 using System.Security.Cryptography.X509Certificates;
 using System.Text;
 using System.Net;
 using System.Net.Security;

 void Start() {
   X509Certificate2 p12 = new X509Certificate2(p12FilePath, password);
   ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //accept anything
 
   HttpWebRequest request = WebRequest.Create("https://www.example.com") as HttpWebRequest;
   request.ClientCertificates.Add(p12);
 
   HttpWebResponse response = request.GetResponse() as HttpWebResponse;
   print(response.StatusDescription);
   Stream dataStream = response.GetResponseStream ();
   StreamReader reader = new StreamReader (dataStream);
   string responseFromServer = reader.ReadToEnd ();
   print(responseFromServer);
 
   reader.Close();
   response.Close();
 }

What the code is doing:

  1. Reading a p12 file off disk

  2. Accepting home rolled certificates

  3. Querying the secure website that requires a certificate to access

  4. Printing the response.

The line where it all goes wrong is

 HttpWebResponse response = request.GetResponse() as HttpWebResponse;

giving the error

 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 WebException: Error: SendFailure (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.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
   at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0 
   at SecureWebAccess.Start () [0x00000] in <filename unknown>:0 


  1. Is there any way to force the precompilation of this or other solutions to get around this issue on iOS?

  2. Or can anyone recommend another networking solution that will allow me to do the same thing?

Thanks.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Jul 20, 2012 at 09:06 PM 0
Share

Ugh you may be in trouble there. $$anonymous$$ono has some weird GetValue implementation that causes a JIT - when you do it yourself you use GetGet$$anonymous$$ethod off the reflected class and call that. I can't figure if this will help (and you could take a look at the link off that article too).

Really not sure if you can register that signature as we don't really know what it is. If you can find it then the stuff in my article may work.

avatar image mindlube · Jul 21, 2012 at 04:15 AM 0
Share

An excellent article, that whydoidoit linked to. Reflection doesn't play nicely with $$anonymous$$ono AOT on iOS. But I'm not sure it's possible to back-engineer the stack trace into Register* and FastInvoke calls as suggested in the article. Because it's part of System.Net.Security or somesuch :(

avatar image Robert-Castle · Jul 21, 2012 at 10:35 AM 0
Share

Thanks. That is what I thought. WebRequest is no go on iOS. Time to dig into Apple's Networking and Security frameworks, and write significantly more code to reproduce the 5 key lines here. Sigh.

avatar image whydoidoit · Jul 21, 2012 at 12:00 PM 0
Share

Well it is certainly possible to convince the compiler to emit the code so there is no JIT - just it's damn hard to work out what it is actually trying to access!

avatar image Paulius-Liekis · Mar 30, 2015 at 07:11 PM 0
Share

$$anonymous$$aybe someone has found a better solution for this?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Robert-Castle · Aug 10, 2012 at 08:05 PM

I gave up trying to figure out if this was possible, and used AFNetworking for iOS instead. Handles everything i need and allows me to manage the download queue easily. Also using native Objective-C allows me to easily use the keychain to securely store the certificates.

The main thing this adventure taught me is this: When adding a new feature that uses a new bit of .Net test it on your target platform ASAP.

This handy compatibility guide is also worth reading if you are poking into the darker corners of Mono.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mindlube · Jul 21, 2012 at 04:17 AM

If you don't use home-rolled SSL certs, does Unity handle the https:// ok? Haven't tried it myself, just suggesting :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Robert-Castle · Jul 21, 2012 at 10:37 AM 0
Share

WWW is fine with regular https requests, where the server provides the certificate. Here I need to provide a certificate to the server to gain access, and I cannot find any information that shows this scenario is possible with the WWW class.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Serialization of Dictionary> in Unity 4,6 0 Answers

My Generic function using LINQ(orderBy thenBy)Not working on IOS 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What C# packages should be avoided to avoid JIT compile errors on iOS 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges