I'm trying to download something with WebClient and DownloadFileAsync in the Unity3D engine and it works on Desktop, I think on iPhone as well but it fails to do so on Android.
Basically this is what I do:
using (var client = new WebClient())
{
client.DownloadFileAsync(new Uri(url), path);
}
And this is the exception I get on my Android 12, Google Pixel 4a phone:
System.Net.WebException: An exception occurred during a WebClient request. ---> System.NullReferenceException: Object reference not set to an instance of an object
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebRequestPrefixElement..ctor (System.String P, System.Type creatorType) [0x00018] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>:0
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebRequest.PopulatePrefixList () [0x00040] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>:0
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebRequest.get_PrefixList () [0x00022] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>:0
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebRequest.Create (System.Uri requestUri, System.Boolean useUriBase) [0x0002e] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>:0
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebRequest.Create (System.Uri requestUri) [0x00014] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>:0
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebClient.GetWebRequest (System.Uri address) [0x00000] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>:0
08-18 18:12:20.138 26647 26666 I Unity : at System.Net.WebClient.DownloadFileAsync (System.Uri address, System.String fileName, System.Object userToken) [0x00032] in <8bb5d2547dc749eeb8bd52a9eb3b67d1>
Could you help me investigating? Thanks!
UPDATE:
This only seems to happen with Mono scripting backend. Now it works once I switched to IL2CPP and checked the ARM64 checkbox due to Unity's suggestion.