Search Unity

[IL2CPP] Exception: Error: called non-existent method System.Collections.Specialized.NameValueCollec

Discussion in 'Android' started by LiefLayer, Aug 9, 2019.

  1. LiefLayer

    LiefLayer

    Joined:
    Jan 6, 2013
    Posts:
    65
    Ok the problem is "simple":
    IL2CPP is missing System.Web.HttpUtility.ParseQueryString method (for what I understand is the full System.Web that is missing).
    It's possible to replace it?
    Will Unity implement it in the future?

    In mono (android) everything works... but with mono I cannot do a 64-bit build.
    Since IL2CPP is the future (and the only supported scripting backend for iOS) I really wish there is a way to workaround this problem.

    Not sure if Unity will add the support for it or I should write it on my own but I really want to solve this problem.

    Right now the problem is with this plugin (not made for Unity):
    https://github.com/gpailler/MegaApiClient/blob/master/MegaApiClient/MegaApiClient.cs
    line 1080.
    I already tried this:
    https://github.com/Cratesmith/RestSharp-for-unity3d/tree/master/RestSharp/Extensions/MonoHttp
    and I already tried this solution:
    Code (CSharp):
    1. private Dictionary<string, string> ParseQueryString(string url) {
    2.     var querystring = url.Substring(url.IndexOf('?') + 1);
    3.     var pairs = querystring.Split('&');
    4.     var dict = pairs.Select(pair => { var valuePair = pair.Split('=');
    5.     return new KeyValuePair<string, string>(valuePair[0], valuePair[1]); }) .ToDictionary((kvp) => kvp.Key, (kvp) => kvp.Value); return dict;
    6. }
    Both are not working.
    I also tried to modify the RestSharp code by copying the original source code of those classes:
    https://github.com/mono/mono/blob/master/mcs/class/System.Web/System.Web/HttpUtility.cs

    But I was only able to get a BadApi response.

    I already had to recompile https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347
    since MegaApiClient require version 10 (and json net for unity is version 8.3 but 100% compatible).

    Any ideas? Thank you.

    PS. After a bit of debugging I even tried
    Code (CSharp):
    1.  UriBuilder builder = new UriBuilder(BaseApiUri);
    2.       var arguments = "";
    3.       foreach (var item in query)
    4.       {
    5.         arguments = arguments + item.Key + "=" + item.Value + "&";
    6.       }
    7.       arguments = arguments.Substring(0, arguments.Length -1);
    8.  
    9.       builder.Query = arguments.ToString();
    10.       return builder.Uri;
    This stupid solution still works on the Editor but it still give an ApiException: BadSessionId on mobile (a MegaApiClient Exception).
    /// API_ESID (-15): Invalid or expired user session, please relogin

    Not sure why at this point.
     
    Last edited: Aug 9, 2019
  2. LiefLayer

    LiefLayer

    Joined:
    Jan 6, 2013
    Posts:
    65
    The stupid solution works but IL2CPP also do same stripping that the old Mono does not (in Mono I can disable stripping, while in IL2CPP the minimum is Low).
    To solve this little (but very annoying problem) you need to create a link.xml file:
    Code (CSharp):
    1. <linker>
    2.    <assembly fullname="MegaApiClient"> // the name of the assembly
    3.       <type fullname="CG.Web.MegaApiClient.*" preserve="all"/> // excludes all namespaces and classes recursively under MyNamespace
    4.    </assembly>
    5. </linker>
    With this everything works again.