# “Method 'System.Net.Logging.get_On' not found” on built application in Unity

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

(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
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.Task1[TResult].InnerInvoke () [0x0000f] 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.TaskAwaiter1[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.TaskAwaiter1[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)

• Did you search for the issue? This seems to be an open problem with some versions of Mono. – DMGregory Mar 11 '18 at 20:59
• @DMGregory I did, but I'm unsure why it works in the editor but not on the standalone application – jjmcc Mar 11 '18 at 21:06
• Downgraded the version to 4.3.1 which seems to work but this produces another error. – jjmcc Mar 11 '18 at 22:09

After some digging I managed to find a solution until this issue is fixed.

Remove all System.Net.Http dlls from the Unity project.

Taken from here, one of the Unity officials

Try putting a file named mcs.rsp in the Assets directory with one line in it:

-r:System.Net.Http.dll

I think that will correctly reference the assembly from the class library directory, and it should work then.

This solves the editor problem and now System.Net.Http is referenced but may not be recognised in Visual Studio. Install it through NuGet and it should be fine.

If I can put in my 2 cents - I had the same issue but more or less found the solution here. In particular, marek-safar's answer:

All versions of System.Net.Http are broken on Mono because they use private API available in .NET assemblies only (bad InternalsVisibleTo). To workaround that Mono has a hack to disable loading such assemblies and use always Mono's ones. You can simply fix it by deleting System.Net.Http.dll from your bin folder or wait for Mono 5.2 with updated table of broken assemblies.

In my case, I have additional projects that perform the Http tasks rather than the main Unity project, so the solution for me was to remove the System.Net.Http.dll` and its reference from said main project (it remains in the additional ones).