System.Net.Http

Can any one help to use 4.6 net.http??


3435430--271624--upload_2018-3-23_10-43-9.png
3435430--271625--upload_2018-3-23_10-43-22.png

Unity Version is 2017.1.1f1,2017.3.1p3.

Can any one help?

You will need to manually add a reference to the System.Net.Http.dll assembly in the .NET class libraries (Unity does not reference it by default). You can do this by adding an mcs.rsp file in the Assets folder of your project with these contents:

-r:System.Net.Http.dll

1 Like

Thanks a lot ~ I have already saw you relay on the same issue in other same forums,But it’s seems only without compile error. When I use HttpClient.setVersion (2,0) ,what I realy want to use http2 to save tcp connection count ,it show me a exception .With the version(1,0) or (1,1) it can run and get the http server data.
I am not sure if I should continue to find a way to use unity dnet4.6 httpclient for my http2 request or find another way …

I’m unsure about the status of http2 support. I would recommend creating a test case which does what you want, then see if it works with .NET outside of Unity. If it does work there, but not in Unity, then please file a bug report.

This gives me:

error CS0006: Metadata file `System.Net.Http.dll' could not be found

Compilation failed: 1 error(s), 0 warnings

Which Scripting Runtime Version and Api Compatibility Level values are you using the the Player Settings?

Nevermind, after I deleted library and temp files this is no longer an issue.
Android, .Net 4.x equivalent, Mono.

1 Like

hi @JoshPeterson – do you have any additional info on the purpose of the mcs.rsp file?

The mcs.rsp file is used to provide additional command line arguments to the C# compiler. In all currently supported versions of Unity, the file should be named csc.rsp, since Unity now uses csc.exe (i.e. Roslyn) as the C# compiler in all cases.

many thanks

hey @JoshPeterson – one additional question, does it matter where i place the actual .dll within the project?

In general no, it does not matter. But which .dll file are you putting in the project? Sorry, I may have missed something.

I’m trying to make use of System.Net.Http.WebRequest.dll. Specifically, the ClientCertificateOptions in the WebRequestHandler

seeing this after doing the unity build

Ahh ok! So should not need to copy System.Net.Http.WebRequest.dll into the Unity project. Just referencing it from the csc.rsp should be enough to use it properly.

1 Like

what’s peculiar is that when running the code within the editor, everything works as expected. i only see this when when doing the actual build

Can you send the text of those error messages? I don’t see all of the text in the screen shot.

gotcha – let me give it a shot without the dll being there

sure, here’s one of the error messages

Reference rewriter: Error: method System.Void System.Net.Http.HttpClientHandler::CheckDisposedOrStarted() doesn’t exist in target framework. It is referenced from System.Net.Http.WebRequest.dll at System.Void System.Net.Http.WebRequestHandler::set_AuthenticationLevel(System.Net.Security.AuthenticationLevel).
0x00007ff762f7c4cc (Unity) StackWalker::GetCurrentCallstack
0x00007ff762f83ac9 (Unity) StackWalker::ShowCallstack
0x00007ff763d1ad5c (Unity) GetStacktrace
0x00007ff76478b677 (Unity) DebugStringToFile
0x00007ff7630fe9ca (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x000001fe805cbd4b (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x000001fe805cbbeb (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[ ])
0x000001fe805cb10e (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x000001fe86ca94ea (Mono JIT Code) UnityEngine.Debug:LogError (object)
0x000001fe86ca2123 (Mono JIT Code) [PostProcessWinRT.cs:1196] PostProcessWinRT:RunReferenceRewriter ()
0x000001fe86a9e9e3 (Mono JIT Code) [PostProcessWinRT.cs:203] PostProcessWinRT:Process ()
0x000001fe86a9724b (Mono JIT Code) [ExtensionModule.cs:86] UnityEditor.UWP.BuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs)
0x000001fe86a96f2e (Mono JIT Code) UnityEditor.Modules.DefaultBuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs,UnityEditor.BuildProperties&)
0x000001fe86a960b2 (Mono JIT Code) UnityEditor.PostprocessBuildPlayer:Postprocess (UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,string,string,string,int,int,UnityEditor.BuildOptions,UnityEditor.RuntimeClassRegistry,UnityEditor.Build.Reporting.BuildReport)
0x000001fe86a96690 (Mono JIT Code) (wrapper runtime-invoke) :runtime_invoke_void_int_int_object_object_object_int_int_int_object_object (object,intptr,intptr,intptr)
0x00007ffeceb700e0 (mono-2.0-bdwgc) [mini-runtime.c:2849] mono_jit_runtime_invoke
0x00007ffeceaf2ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
0x00007ffeceafbb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
0x00007ff762ec0754 (Unity) scripting_method_invoke
0x00007ff762ebb851 (Unity) ScriptingInvocation::Invoke
0x00007ff7649d65fa (Unity) CallMono
0x00007ff7649dda58 (Unity) PostprocessPlayer
0x00007ff7649d9030 (Unity) DoBuildPlayer_PostBuild
0x00007ff7649d7780 (Unity) DoBuildPlayer
0x00007ff7649cc2ca (Unity) BuildPlayer
0x00007ff764348704 (Unity) BuildPipeline::BuildPlayerInternalNoCheck
0x00007ff7642a9f5f (Unity) BuildPipeline_CUSTOM_BuildPlayerInternalNoCheck
0x000001fe868ff63c (Mono JIT Code) (wrapper managed-to-native) UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck (string[ ],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,UnityEditor.BuildOptions,string[ ],bool)
0x000001fe868c7733 (Mono JIT Code) UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
0x000001fe868be96b (Mono JIT Code) UnityEditor.BuildPlayerWindow:CallBuildMethods (bool,UnityEditor.BuildOptions)
0x000001fe868bdf6b (Mono JIT Code) UnityEditor.BuildPlayerWindow:BuildPlayerAndRun (bool)
0x000001fe868b90f3 (Mono JIT Code) UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
0x000001fe80737315 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
0x00007ffeceb700e0 (mono-2.0-bdwgc) [mini-runtime.c:2849] mono_jit_runtime_invoke
0x00007ffeceaf2ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
0x00007ffeceafbb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
0x00007ff762eb7f9e (Unity) CallStaticMonoMethod
0x00007ff762eb7d51 (Unity) CallStaticMonoMethod
0x00007ff7639c568f (Unity) BuildPlayerWithLastSettings
0x00007ff7636efe2d (Unity) MenuController::ExecuteMenuItem
0x00007ff7636ef57f (Unity) MenuController::ExecuteMainMenuItem
0x00007ff76432f55e (Unity) EditorApplication_CUSTOM_ExecuteMenuItem
0x000001fe868b8bde (Mono JIT Code) (wrapper managed-to-native) UnityEditor.EditorApplication:ExecuteMenuItem (string)
0x000001fe868b8aab (Mono JIT Code) UnityEditor.ShortcutManagement.MenuItemEntryDiscoveryInfo:<.ctor>b__7_0 (UnityEditor.ShortcutManagement.ShortcutArguments)
0x000001fe868b2041 (Mono JIT Code) UnityEditor.ShortcutManagement.Trigger:HandleKeyEvent (UnityEngine.Event,UnityEditor.ShortcutManagement.IContextManager)
0x000001fe868aff53 (Mono JIT Code) UnityEditor.ShortcutManagement.ShortcutController:HandleKeyEvent (UnityEngine.Event)
0x000001fe868afa93 (Mono JIT Code) UnityEditor.ShortcutManagement.ShortcutIntegration:EventHandler ()
0x000001fe868af66e (Mono JIT Code) UnityEditor.EditorApplication:Internal_CallGlobalEventHandler ()
0x000001fe80737315 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
0x00007ffeceb700e0 (mono-2.0-bdwgc) [mini-runtime.c:2849] mono_jit_runtime_invoke
0x00007ffeceaf2ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
0x00007ffeceafbb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
0x00007ff762ec0754 (Unity) scripting_method_invoke
0x00007ff762ebb851 (Unity) ScriptingInvocation::Invoke
0x00007ff762eb5615 (Unity) ScriptingInvocation::Invoke
0x00007ff76215d76b (Unity) Scripting::UnityEditor::EditorApplicationProxy::Internal_CallGlobalEventHandler
0x00007ff7637c553a (Unity) CallGlobalInputEvent
0x00007ff763d535da (Unity) GUIView::ProcessEventMessages
0x00007ff763d4d06d (Unity) GUIView::GUIViewWndProc
0x00007fff25b41c4c (USER32) CallWindowProcW
0x00007fff25b40ea6 (USER32) DispatchMessageW
0x00007ff763d210c6 (Unity) MainMessageLoop
0x00007ff763d253b1 (Unity) WinMain
0x00007ff7653f326e (Unity) __scrt_common_main_seh
0x00007fff25425550 (KERNEL32) BaseThreadInitThunk
0x00007fff265a485b (ntdll) RtlUserThreadStart

i’m on unity 2020.3.40f1 btw