C# 为什么在windows 7中运行我的应用程序时获取System.Net.Http.HttpRequestException

C# 为什么在windows 7中运行我的应用程序时获取System.Net.Http.HttpRequestException,c#,.net,wpf,httpclient,async-await,C#,.net,Wpf,Httpclient,Async Await,我正在开发一个WPF应用程序,它可以使用Http客户端与我的服务器通信 我的应用程序建立在.NET4上。我通过nugget安装Http客户端。我还安装了 Microsoft.CompilerServices.AsyncTargetingPack通过nugget 在Windows8中,它可以正常工作。但在Windows7中,我得到了一个例外 应用程序:whost.Generator.Creator.exe框架版本:v4.0.30319 描述:由于未处理的异常,进程已终止。 异常信息:System.

我正在开发一个WPF应用程序,它可以使用Http客户端与我的服务器通信

我的应用程序建立在.NET4上。我通过nugget安装Http客户端。我还安装了 Microsoft.CompilerServices.AsyncTargetingPack通过nugget

在Windows8中,它可以正常工作。但在Windows7中,我得到了一个例外

应用程序:whost.Generator.Creator.exe框架版本:v4.0.30319 描述:由于未处理的异常,进程已终止。 异常信息:System.Net.Http.HttpRequestException堆栈:

服务器堆栈跟踪:

在[0]处重试异常:在 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccess(任务 任务)在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中 在 whost.Generator.Creator.Basic.ServerCommunicator.d_u10.MoveNext()

[1]处的异常重试:在 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccess(任务 任务)在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中 在 whost.Generator.Creator.ViewModel.LicenseGenerateViewModel.d_3.MoveNext() 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.b_0(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, 对象,Int32)在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate,System.Object,Int32,System.Delegate)位于 System.Windows.Threading.DispatcherOperation.InvokeImpl()位于 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 位于的System.Threading.ExecutionContext.runTryCode(System.Object) System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, 清除代码,System.Object)位于 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)位于 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,布尔值)位于 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)位于 System.Windows.Threading.DispatcherOperation.Invoke()位于 位于的System.Windows.Threading.Dispatcher.ProcessQueue() System.Windows.Threading.Dispatcher.WndProcHook(IntPtr、Int32、IntPtr、, 在MS.Win32.HwndWrapper.WndProc(IntPtr, Int32,IntPtr,IntPtr,Boolean ByRef)在 位于的MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, 对象,Int32)在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate,System.Object,Int32,System.Delegate)位于 System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan、System.Delegate、System.Object、Int32)位于 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr)
在 MS.Win32.UnsafentiveMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)在 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 位于System.Windows.Threading.Dispatcher.Run()的 System.Windows.Application.RunDispatcher(System.Object)位于 System.Windows.Application.RunInternal(System.Windows.Window)位于 System.Windows.Application.Run(System.Windows.Window)位于 System.Windows.Application.Run()位于 whost.Generator.Creator.App.Main()

我不明白为什么我会得到这个例外。 我的服务器是基于MVC4和WebAPI构建的

提前谢谢

更新1: 我的代码是:

    var handler = new HttpClientHandler();
    var cookieContainer = new CookieContainer();
    handler.CookieContainer = cookieContainer;
    var client = new HttpClient(handler) { BaseAddress = new Uri("http://myhost.com/") };
    client.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("application/json"));
    var loginModel = new LoginModel
       {
         UserName = Username,
         Password = Password,
       };
    var userLoginResposnce = await client.PostAsJsonAsync("account/Login", loginModel);
    var successInfoTamplate = new { Success = true };
    var loginResponceString = await userLoginResposnce.Content.ReadAsStringAsync();
    var isSuccess = JsonConvert.DeserializeAnonymousType(loginResponceString, successInfoTamplate);

我在Windows 7 PC上安装了.NET 4。

这不是因为您的计算机上安装了.NET framework吗?您是否已在windows 7上将.net framework更新为最新版本?是否可以发布引发错误的代码的相关部分?堆栈跟踪非常好,但是如果没有上下文(代码),它也非常无用。