mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
WireMock.Net.AspNetCore.Middleware does not work in hosted services #685
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @etkr on GitHub (Apr 24, 2025).
Describe the bug
WireMock AspNetCore Middleware works great when a request is sent from within a request thread, but if a request is sent from a background service it throws this exception:
What is happening is that
HttpContextis not available in a hosted service, it is a nullable property ofIHttpContextAccessorsince it is not always guaranteed to be available.Expected behavior:
It should be possible to make http requests in a background service while WireMock Middleware is enabled.
Additionally it should be possbile to mock requests coming from a background service.
Test to reproduce
AddWireMockServiceArgumentNullExceptionis thrown fromHttpClientOther related info
I created a PR #1285 with a test that reproduces this bug and a proposed solution.