Skip to content

InvalidOperationException while using AddExtendedHttpClientLogging #7649

Description

@viorelbuligadev

Description

Extended HTTP logging breaks stream reads in Debug mode (.NET, Microsoft.Extensions.Http.Diagnostics 9.1+)
When using AddExtendedHttpClientLogging with HttpClient.GetAsync, reading the response stream in Debug mode throws InvalidOperationException: The stream was already consumed. Release mode is unaffected. Reproduced on 9.1+; not present on 9.0. Fix: use SendAsync with HttpCompletionOption.ResponseHeadersRead instead of GetAsync.

more info here: https://viorelbuliga.com/blog/extended-http-logging-stream-consumed
repro steps: https://github.com/viorelbuligadev/StreamConsumedRepro

Reproduction Steps

https://github.com/viorelbuligadev/StreamConsumedRepro

Expected behavior

using AddExtendedHttpClientLogging() should not throw any exceptions

Actual behavior

using AddExtendedHttpClientLogging() throw exception, check the git repo

Regression?

Reproduced on Microsoft.Extensions.Http.Diagnostics 9.1+; not present on 9.0.

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue describes a behavior which is not expected - a bug.untriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions