I have a Unity application that uses System.Net.Http
to fetch data from an API. I am using Unity 2017.3.1f1 and .NET 4.6 and this works perfectly fine in the editor and the application builds fine, however the requests do not work on the built version of the application.
I'd expect the results to be shown on the screen, however I am receiving the "Method 'System.Net.Logging.get_On' not found" error and the requests failed.
This only happens on the built version and not the editor. Does anyone know why this is happening?
Mono version: 5.0.1 (Visual Studio built mono)
EDIT
Apparently this could be an issue with System.Net.Http 4.3.2/4.3.3, I have downgraded to version 4.3.1 which seems to work and doesn't throw this error, but now I get Loading script assembly "Assets/Lib/SystemHttp/System.Net.Http.dll" failed!
when running the standalone application. Again this works fine in the editor.
Usually I'd get this if the dll wasn't compatible, however it is targetting .NET 4.6, and this seems to be the only dll that was included in this release.
EDIT
I enabled logging for the production build and this is what I get
Failed loading assembly Managed/System.Net.Http.dll
Loading script assembly "Managed/System.Net.Http.dll" failed!
(Filename: C:\buildslave\unity\build\Runtime/Mono/MonoManager.cpp Line: 964)
- Completed reload, in 0.047 seconds
<RI> Initializing input.
<RI> Input initialized.
<RI> Initialized touch support.
Setting up 4 worker threads for Enlighten.
Thread -> id: 316c -> priority: 1
Thread -> id: 3394 -> priority: 1
Thread -> id: 3b28 -> priority: 1
Thread -> id: 3bb8 -> priority: 1
UnloadTime: 1.029624 ms
BadImageFormatException: Could not resolve field token 0x040000a3, due to: Could not load type of field 'LobbyInitializer+<getServer>c__async8:<request>__1' (1) due to: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. assembly:System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:<unknown type> member:<none> assembly:Assembly-CSharp.dll type:<getServer>c__async8 member:<none>
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Threading.Tasks.Task.Execute () [0x00010] in <c95265f74fdf4905bfb0d5a4b652216c>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at LobbyInitializer+<getServer>c__async1.MoveNext () [0x00082] in LobbyInitializer.cs:42
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at LobbyInitializer+<findServersAsync>c__async0.MoveNext () [0x0007c] in LobbyInitializer.cs:36
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <c95265f74fdf4905bfb0d5a4b652216c>:0
at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00001] in <4b58939e897a4c34942efe344ae250a9>:0
at UnityEngine.UnitySynchronizationContext.Exec () [0x00021] in <4b58939e897a4c34942efe344ae250a9>:0
at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00012] in <4b58939e897a4c34942efe344ae250a9>:0
(Filename: <c95265f74fdf4905bfb0d5a4b652216c> Line: 0)
4.3.1
which seems to work but this produces another error. \$\endgroup\$