.WithBodyFromFile() + .WithTransformer(transformContentFromBodyAsFile: true) = empty string #635

Closed
opened 2025-12-29 15:29:24 +01:00 by adam · 4 comments
Owner

Originally created by @vitalyve on GitHub (Sep 28, 2024).

Originally assigned to: @StefH on GitHub.

Describe the bug

When .WithBodyFromFile(responseFilePath) is used in combination with .WithTransformer(transformContentFromBodyAsFile: true) the server returns empty string.

Expected behavior:

The server should return transformed contents of the file.

Test to reproduce

I've created a project with tests to demonstrate the problem. Please look at it.
https://github.com/vitalyve/WireMockNetBodyFromFileWithTransformerBug

Originally created by @vitalyve on GitHub (Sep 28, 2024). Originally assigned to: @StefH on GitHub. ### Describe the bug When .WithBodyFromFile(responseFilePath) is used in combination with .WithTransformer(transformContentFromBodyAsFile: true) the server returns empty string. ### Expected behavior: The server should return transformed contents of the file. ### Test to reproduce I've created a project with tests to demonstrate the problem. Please look at it. https://github.com/vitalyve/WireMockNetBodyFromFileWithTransformerBug
adam added the bug label 2025-12-29 15:29:24 +01:00
adam closed this issue 2025-12-29 15:29:25 +01:00
Author
Owner

@vitalyve commented on GitHub (Sep 29, 2024):

Hi.
After some debugging of the WireMock.Net I've found that .WithTransformer(transformContentFromBodyAsFile: true) should be placed before .WithBodyFromFile() to be able to work as expected, but in examples form the Wiki it is placed after .WithBodyFromFile().
So, just need to update the article and the issue may be closed.
Anyway, thank you for the great project!

@vitalyve commented on GitHub (Sep 29, 2024): Hi. After some debugging of the WireMock.Net I've found that .WithTransformer(transformContentFromBodyAsFile: true) should be placed before .WithBodyFromFile() to be able to work as expected, but in examples form the [Wiki](https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating) it is placed after .WithBodyFromFile(). So, just need to update the article and the issue may be closed. Anyway, thank you for the great project!
Author
Owner

@StefH commented on GitHub (Sep 29, 2024):

Yes. I just made a branch with your testcase.

And indeed the order is important. However from a user perspective it should always work.

I will check if I can update the code.

@StefH commented on GitHub (Sep 29, 2024): Yes. I just made a branch with your testcase. And indeed the order is important. However from a user perspective it should always work. I will check if I can update the code.
Author
Owner

@StefH commented on GitHub (Sep 29, 2024):

Changing the internal logic is some work.

Adding a check and throw exception is better for now.

See PR:
https://github.com/WireMock-Net/WireMock.Net/pull/1185

@StefH commented on GitHub (Sep 29, 2024): Changing the internal logic is some work. Adding a check and throw exception is better for now. See PR: https://github.com/WireMock-Net/WireMock.Net/pull/1185
Author
Owner

@vitalyve commented on GitHub (Sep 29, 2024):

Thank you!

@vitalyve commented on GitHub (Sep 29, 2024): Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#635