aws-sdk-net: UnityWebRequest failing on IL2CPP Android in Unity 2017.1.0f3
Expected Behavior
UnityWebRequest static constructor should not throw exceptions.
Current Behavior
UnityWebRequest throws a null reference exception.
E/Unity: System.TypeInitializationException: The type initializer for 'Amazon.Runtime.Internal.UnityWebRequestWrapper' threw an exception. ---> System.NullReferenceException: A null value was found where an object instance was required. at Amazon.Runtime.Internal.UnityWebRequestWrapper..cctor () [0x00000] in <filename unknown>:0 at Amazon.AWSConfigs.set_HttpClient (HttpClientOption value) [0x00000] in <filename unknown>:0
The error is non-descriptive so I investigated. The error is thrown in the static constructor of UnityWebRequestWrapper at the line
PropertyInfo isErrorProperty = unityWebRequestType.GetProperty("isError");
The isError property is obsolete in Unity2017 and has been replaced with isNetworkError https://docs.unity3d.com/2017.1/Documentation/ScriptReference/Networking.UnityWebRequest-isNetworkError.html
Possible Solution
In my own project I changed isError to isNetworkError in the UnityWebRequestWrapper, rebuilt the Core.dll and that resolved the issue. You could do something similar while also taking care of backwards compatibility.
Steps to Reproduce (for bugs)
In Unity 2017.1.0f3, create a Start() method with this content
UnityInitializer.AttachToGameObject(gameObject);
AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
The AWSConfigs.HttpClient setter will call the static constructor of UnityWebRequestWrapper and you will get an exception if you’re running IL2CPP Android.
Context
I was trying to upload data to an S3 bucket.
Your Environment
- AWSSDK.Core version used: 3.3.124.0
- Service assembly and version used:
- Operating System and version: Windows 10 Home 64-Bit
- Visual Studio version: Visual Studio Community 2017
- Targeted .NET platform: 3.5
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (3 by maintainers)
@infernova
Can you create a file in Assets/Resources called link.xml and place this code in it: https://pastebin.com/HZn86hN6
Let me know how that works for you
@infernova That’s what I suspected. Glad it’s working for you now!