FlurlClient throws a NullReferenceException when disposing

Created on 26 Jun 2018  路  2Comments  路  Source: tmenier/Flurl

Hi,

I am having this issue where the disposing of the client fails because of the mentioned exception. The simplest way to repro is the following class. I am using the latest versions of Flurl and Flurl.Http:

The actual code:

    public sealed class TestServerFixture : IDisposable
    {
        private readonly TestServer _server;
        private HttpClient _client;
        public IFlurlClient Client { get; }

        public TestServerFixture()
        {
            _server = new TestServer(
                Program.BuildWebHost());
            _client = _server
                .CreateClient();
            Client = new FlurlClient(_client);
        }

        public void Dispose()
        {
            _client.Dispose();
            Client.Dispose();
            _server.Dispose();
        }
    }

This show where it fails:

image

As you can see from the coverage on the left hand side, the client disposing itself does not fail, but the FlurlClient does fail. I looked at the code and it looks like we do not check that the value in the Lazy is not null, but I don't know if that is the reason of the bug.

bug

Most helpful comment

Confirmed. Thanks for reporting. Will fix this for the next maintenance release.

All 2 comments

Confirmed. Thanks for reporting. Will fix this for the next maintenance release.

Was this page helpful?
0 / 5 - 0 ratings