NullReferenceException when make a PUT request using Flurl

0

I'm constructing a Url and making an PUT request using Flurl, as follows:

using (var client = new Url("myurl"))
    .ConfigureClient(c => c.HttpClientFactory = new CompressHttpClientFactory())
    .WithCookie(new System.Net.Cookie("name", "value", "/", "domain"))
{
    var content = new StringContent("json here", Encoding.UTF8, "application/json");
    var response = await client.PutAsync(content)
}

But I'm getting an exception when calling PutAsync:

System.NullReferenceException occurred HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Flurl.Http StackTrace: at Flurl.Http.FlurlClient.ReadResponseCookies(HttpResponseMessage response) at Flurl.Http.FlurlClient.d__28.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Should I use try / catch and ignore the exception?

c#
http
flurl

1 Answer

0

I suspect that the actual HTTP call is failing to get a response, and Flurl is trying to read the cookies anyway without doing a null check on the response. This is a known bug and is fixed/ready for the 2.0 release. 2.0 is in prerelease right now and I recommend upgrading. It's stable for production use, I'm just not guaranteeing quite yet that the changes are set in stone.

answered on Stack Overflow Sep 28, 2017 by Todd Menier

User contributions licensed under CC BY-SA 3.0