Error thrown when calling mocked endpoint second time when using file-based response body #190

Closed
opened 2025-12-29 08:23:39 +01:00 by adam · 1 comment
Owner

Originally created by @rwwilden on GitHub (Jul 22, 2019).

When you use a setup as follows:

server
  .Given(
      Request
          .Create()....)
  .RespondWith(
      Response
          .Create().....
          .WithBodyFromFile(fileName));

the mocked endpoint can only be called successfully the first time. Second time it will throw an error.

This is caused by the fact that the property BodyData.BodyAsFile is set to null right after the first successful response, causing an ArgumentNullException the second time. This happens in the Response class.

Originally created by @rwwilden on GitHub (Jul 22, 2019). When you use a setup as follows: server .Given( Request .Create()....) .RespondWith( Response .Create()..... .WithBodyFromFile(fileName)); the mocked endpoint can only be called successfully the first time. Second time it will throw an error. This is caused by the fact that the property `BodyData.BodyAsFile` is set to `null` right after the first successful response, causing an `ArgumentNullException` the second time. This happens in the [`Response`](https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/ResponseBuilders/Response.cs#L422) class.
adam added the bug label 2025-12-29 08:23:39 +01:00
adam closed this issue 2025-12-29 08:23:39 +01:00
Author
Owner

@StefH commented on GitHub (Jul 22, 2019):

Dankjewel.

@StefH commented on GitHub (Jul 22, 2019): Dankjewel.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#190