Search Issue Tracker

Fixed in 2021.2.X

Votes

0

Found in

2020.1

2020.1.9f1

2020.2

2021.1

2021.2

Issue ID

1296177

Regression

No

[android] HttpUtility Null reference exception on .net 4.x when performing HttpUtility.UrlEncode

Mono

-

How to reproduce:
1. Build and run the "Http test.zip" Project on an Android device
2. Check the logs once the Project fully loads

Expected Behavior: The method is executed without errors
Actual Behavior: Null reference or "called non-existent method System.String System.Web.HttpUtility" exception is thrown

Reproducible with: 2020.1.17f1, 2020.2.2f1, 2021.1.0b2, 2021.2.0a2

Reproducible with devices:
Xiaomi 9T (customer's device)
VLNQA00015, Samsung Galaxy Note8 (SM-N950W), Android 8.0.0, CPU: Snapdragon 835 MSM8998, GPU: Adreno (TM) 540
VLNQA00286, Meizu - (PRO 5), Android 7.0, CPU: Exynos 7 Octa 7420, GPU: Mali-T760

Note:
- The customer had two different exceptions (added them in the case edits)
- Only reproducible on android

  1. Resolution Note (fix version 2021.2):

    Fixed 2021.2.0a8

Comments (4)

  1. longsl

    Apr 26, 2022 14:57

    Alternative in old unity version: https://stackoverflow.com/a/72016123/7739839

    don't including a dependency on System.Web. Another way to do this is:
    ```
    NameValueCollection queryParameters = new NameValueCollection();
    string[] querySegments = queryString.Split('&');
    foreach(string segment in querySegments)
    {
    string[] parts = segment.Split('=');
    if (parts.Length > 0)
    {
    string key = parts[0].Trim(new char[] { '?', ' ' });
    string val = parts[1].Trim();

    queryParameters.Add(key, val);
    }
    }
    ```

  2. longsl

    Apr 26, 2022 14:25

    same problem in 2020.3.30f1c1

  3. stamatian

    Jul 16, 2021 07:57

    Ok I found a solution. I used WebUtility.UrlEncode instead of HttpUtility.UrlEncode and it works now!

  4. stamatian

    Jul 15, 2021 16:33

    Hi is there a workaround for older versions? I'm using Unity 2021.1.15f and I can't upgrade my project. I noticed that in 2021.2.0b3 there isn't this error... Ho can I fix this without upgrading?

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.