C# 引发异常:';HttpRequestException';在Lumia 950XL设备上测试时,在System.Private.CoreLib.ni.dll中

C# 引发异常:';HttpRequestException';在Lumia 950XL设备上测试时,在System.Private.CoreLib.ni.dll中,c#,uwp,azure-sql-database,azure-mobile-services,template10,C#,Uwp,Azure Sql Database,Azure Mobile Services,Template10,现在,当我在本地计算机上的本地数据库上调试我的应用程序时,当我登录到我的应用程序时,我的应用程序工作正常 但是,当我尝试在我的Lumia 950XL上测试它时,有时它成功登录,而另一次我根本没有登录,并向我显示: 单步执行:单步执行非用户代码 'Ceneam.Common.Helpers.AuthenticationDelegatingHandler.CloneHttpRequestMessageAsync' 单步执行:单步执行非用户代码 'Ceneam.Common.Helpers.Authe

现在,当我在本地计算机上的本地数据库上调试我的应用程序时,当我登录到我的应用程序时,我的应用程序工作正常

但是,当我尝试在我的Lumia 950XL上测试它时,有时它成功登录,而另一次我根本没有登录,并向我显示:

单步执行:单步执行非用户代码 'Ceneam.Common.Helpers.AuthenticationDelegatingHandler.CloneHttpRequestMessageAsync' 单步执行:单步执行非用户代码 'Ceneam.Common.Helpers.AuthenticationDelegatingHandler.d__1..ctor' 单步执行:单步执行非用户代码 'Ceneam.Common.Helpers.AuthenticationDelegatingHandler.n___0'步骤 进入:跨过非用户代码 “Ceneam.Common.Helpers.LoggingHandler.SendAsync”单步执行:单步执行 在非用户代码之上 'Ceneam.Common.Helpers.LoggingHandler.d_u2..ctor'
请求:获取, ?$skip=0和$top=25步 进入:跨过非用户代码 “Ceneam.Common.Helpers.LoggingHandler.n_u0”15:17:54.3412524 Template10 HamburgerMenu.GotFocus Windows.UI.Xaml.Controls.Button 名称:汉堡按钮符号:Windows.UI.Xaml.Controls.FontIcon
引发异常:中的“System.Net.Http.HttpRequestException” System.Private.CoreLib.ni.dll(此列表行连续4次)

现在,我已将我的应用程序调试到AuthenticationDelegatingHandler类,下面是它的代码:

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
    //Clone the request in case we need to use it.
    var clone = await CloneHttpRequestMessageAsync(request);

    //Now do the request
    var response = await base.SendAsync(request, cancellationToken);/*after pressing the next step it steps out and returns me to my login page again*/

    if(response.StatusCode == HttpStatusCode.Unauthorized)
    {
        /*The request result in a 401 Unauthorized. We need to do a LoginAsync.
         which will do the Refresh if appropiate, or ask for credentials if not.*/
        var user = await ServiceLocator.Instance.Resolve<ICloudService>().LoginAsync();

        /*Now retry the request with the cloned request. The only thing we have
         to do is replace the X-ZUMO-AUTH header with the new auth token.*/
        clone.Headers.Remove("X-ZUMO-AUTH");
        clone.Headers.Add("X-ZUMO-AUTH", user.MobileServiceAuthenticationToken);
        response = await base.SendAsync(clone, cancellationToken);
    }

    return response;
}
protectedoverride async Task sendaync(HttpRequestMessage请求,CancellationToken CancellationToken)
{
//克隆请求以防我们需要使用它。
var clone=await CloneHttpRequestMessageAsync(请求);
//现在做这个请求
var response=wait base.sendaync(request,cancellationToken);/*在按下下一步后,它会退出并再次返回我的登录页面*/
if(response.StatusCode==HttpStatusCode.Unauthorized)
{
/*请求导致401未经授权。我们需要进行LoginAsync。
如果合适,将刷新,如果不合适,将请求凭据*/
var user=await ServiceLocator.Instance.Resolve().LoginAsync();
/*现在用克隆的请求重试该请求。我们仅有的
要做的是用新的AUTH令牌替换X-ZUMO-AUTH头*/
clone.Headers.Remove(“X-ZUMO-AUTH”);
clone.Headers.Add(“X-ZUMO-AUTH”,user.MobileServiceAuthenticationToken);
response=wait base.sendaync(克隆、取消令牌);
}
返回响应;
}
现在我不是azure方面的专家,但我不明白为什么它只发生在我的手机上,而不发生在桌面上,而且这个异常并不能告诉我太多,而且奇怪的是,我一回到家,它就可以在家里正常工作,它可以顺利地登录。 但这里的工作不是


我已经为测试目的配置了本地服务器,它工作得很好,这只是登录问题。

如果您用try-catch块包围代码并发布实际的异常数据会更好。我已经按照您说的做了,它这样说:[AuthenticationDelegatingHandler]SendAsync方法出错:发送请求时出错。使用try-catch块。请求:GET,抛出异常:System.Private.CoreLib.ni.dll中的“System.Net.Http.HttpRequestException”,抛出异常:System.Private.CoreLib.ni.dll中的“System.Net.Http.HttpRequestException”[AuthenticationDelegatingHandler]SendAsync方法错误:发送请求时出错。引发异常:System.Private.CoreLib.ni.dll中的System.InvalidOperationException引发异常:System.Private.CoreLib.ni.dll中的System.InvalidOperationException[Login]Error=处理程序未返回响应消息。EP。SendAsync和随后的ReceiveAsync(猜测)没有等待服务器的回复,另外,
if语句
只捕获了一件事,如果响应中有更多的内容,比如您可能会遇到的错误,那该怎么办呢?如果您在代码中加入一个try-catch块并发布实际的异常数据会更好。我已经按照您说的做了,它说:[AuthenticationDelegatingHandler]SendAsync方法出错:发送请求时出错。使用try-catch块。请求:GET,抛出异常:System.Private.CoreLib.ni.dll中的“System.Net.Http.HttpRequestException”,抛出异常:System.Private.CoreLib.ni.dll中的“System.Net.Http.HttpRequestException”[AuthenticationDelegatingHandler]SendAsync方法错误:发送请求时出错。引发异常:System.Private.CoreLib.ni.dll中的System.InvalidOperationException引发异常:System.Private.CoreLib.ni.dll中的System.InvalidOperationException[Login]Error=处理程序未返回响应消息。EP。SendAsync和随后的ReceiveAsync(猜测)并没有等待服务器的回复,而且
if语句
只捕获了一件事,如果响应中有更多的内容,比如您可能会遇到的错误,该怎么办。