简体   繁体   English

在FlUrl中我尝试使用EnableCookies()并抛出一个空引用异常

[英]in FlUrl I try to use EnableCookies() and it throw a null reference exception

when I try to execute: 当我尝试执行时:

            using (var fc = new FlurlClient().EnableCookies())
            {
                var resp = "http://somesite.com".GetAsync();
                // var getResp = await "http://api.foo.com".GetAsync();

                var resultado = await resp;

                var x = resultado;
            }

I get a null reference exception on EnableCookies() 我在EnableCookies()上得到一个空引用异常

stack: 堆:

   en Flurl.Url.op_Implicit(Url url) en C:\Aldenteware\Flurl\code\Flurl\Url.cs:línea 315
   en Flurl.Http.CookieExtensions.GetCookieContainer(FlurlClient client) en C:\Aldenteware\Flurl\code\Flurl.Http.Shared\CookieExtensions.cs:línea 145
   en Flurl.Http.CookieExtensions.EnableCookies(FlurlClient client) en C:\Aldenteware\Flurl\code\Flurl.Http.Shared\CookieExtensions.cs:línea 23
   en AfipProcesa.Form1.<flurlAsync>d__0.MoveNext() en c:\Users\fabian.LH\Documents\Visual Studio 2013\Projects\AfipProcesa\AfipProcesa\Form1.cs:línea 86
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   en AfipProcesa.Form1.<button1_Click>d__7.MoveNext() en c:\Users\fabian.LH\Documents\Visual Studio 2013\Projects\AfipProcesa\AfipProcesa\Form1.cs:línea 119
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__4(Object state)

I have to do something more or in another way? 我必须做更多或其他方式的事情?

I put it on a flurl error handler but it not catch it (as it is a null ex) 我把它放在一个flurl错误处理程序,但它没有捕获它(因为它是一个null ex)

I starting to use await/async and flurl at same time... sorry if I'm making a basic mistake. 我开始同时使用await / async和flurl ...对不起,如果我犯了一个基本错误。

I using as a example the code on http://tmenier.github.io/Flurl/client-lifetime/ 我以http://tmenier.github.io/Flurl/client-lifetime/上的代码为例

using (var fc = new FlurlClient().EnableCookies())
{
    await url
        .AppendPathSegment("login")
        .WithClient(fc)
        .PostUrlEncodedAsync(new { user = "user", pass = "pass" });

    var page = await url
        .AppendPathSegment("home")
        .WithClient(fc)
        .GetStringAsync();

    // Need to inspect the cookies? FlurlClient exposes them as a dictionary.
    var sessionId = fc.Cookies["session_id"].Value;
}

It looks like you've spotted a bug related to recent changes to address this issue . 您似乎发现了与最近更改相关的错误以解决此问题 The work-around is to seed FlurlClient with the base URL: 解决方法是使用基本URL为FlurlClient提供种子:

using (var fc = new FlurlClient(url).EnableCookies())

I'll log this issue and address it soon, it clearly doesn't work as documented. 我将记录此问题并尽快解决,但显然无法记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否应引用null变量引发异常 - Should a reference to a null variable throw exception 为什么这会引发空引用异常? - Why does this throw a null reference exception? 如果我尝试在父类中使用TransactionScope,为什么EF&NUnit会引发异常? - Why does EF & NUnit throw an Exception if I try and use TransactionScope in a parent class? 客户端计算机:在Flurl.Http.FlurlClient.ReadResponseCookies上引发NullReference异常 - Client Machine : throw NullReference Exception at Flurl.Http.FlurlClient.ReadResponseCookies 什么时候遍历列表会引发Null Reference Exception? - When does looping through a list throw a Null Reference Exception? 为什么会话对象抛出空引用异常? - Why does session object throw a null reference exception? 使用List(Of Entity)绑定到DataGridView Datasource属性会引发空引用异常 - Binding to DataGridView Datasource property with List(Of Entity) throw a null reference exception 为什么这个嵌套对象初始化器抛出一个空引用异常? - Why does this nested object initializer throw a null reference exception? 当我在模型类中使用导航属性时,Null Reference Exception - Null Reference Exception when i use navigation property in model class 扔哪个Null Exception? - Which Null Exception to throw?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM