WireMock Server does not appear to function correctly with Microsoft.Extensions v3.1 #239

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

Originally created by @dalmuti509 on GitHub (Dec 23, 2019).

If project nuget packages are updated to include Microsoft.Extensions v3.1 nuget libraries, the WireMock server seems to stop correctly responding to requests as all responses result in an invalid format status code 0 when responses are received from HttpClient.

Simple repro which returns 0 after an extended timeout:

            Server.Given(
               Request.Create()
                   .WithPath($"*")
                   .UsingGet()
             )
             .RespondWith(
               Response.Create()
                 .WithStatusCode(HttpStatusCode.OK)
                 .WithBody("{}")
             );

            HttpClient client = new HttpClient();
            var result = client.GetAsync(Server.Urls.First()).Result;
            result.StatusCode.Should().Be(HttpStatusCode.OK);  //Use FluentAssertions

This can be run on line 14 at: WireMock.Net/examples/WireMock.Net.StandAlone.Net461/Program.cs

Update the project to the latest nugets to see the failure.

Originally created by @dalmuti509 on GitHub (Dec 23, 2019). If project nuget packages are updated to include Microsoft.Extensions v3.1 nuget libraries, the WireMock server seems to stop correctly responding to requests as all responses result in an invalid format status code 0 when responses are received from HttpClient. Simple repro which returns 0 after an extended timeout: ``` Server.Given( Request.Create() .WithPath($"*") .UsingGet() ) .RespondWith( Response.Create() .WithStatusCode(HttpStatusCode.OK) .WithBody("{}") ); HttpClient client = new HttpClient(); var result = client.GetAsync(Server.Urls.First()).Result; result.StatusCode.Should().Be(HttpStatusCode.OK); //Use FluentAssertions ``` This can be run on line 14 at: WireMock.Net/examples/WireMock.Net.StandAlone.Net461/Program.cs Update the project to the latest nugets to see the failure.
adam added the question label 2025-12-29 08:24:33 +01:00
adam closed this issue 2025-12-29 08:24:33 +01:00
Author
Owner

@jlobec commented on GitHub (Feb 20, 2020):

Should an "await" be used instead of ."Result" when getting the HttpClient response on this snippet? AFAIK the .Result is only correct if you're absolutely sure that the task is already completed (which I'm afraid is not the case) and could cause deadlocks
Maybe not directly related with the issue topic but will save time in the future :)

@jlobec commented on GitHub (Feb 20, 2020): Should an "await" be used instead of ."Result" when getting the HttpClient response on this snippet? AFAIK the .Result is only correct if you're absolutely sure that the task is already completed (which I'm afraid is not the case) and could cause deadlocks Maybe not directly related with the issue topic but will save time in the future :)
Author
Owner

@StefH commented on GitHub (Feb 20, 2020):

Could be.
Better code should be '.GetAwaiter().GetResult()' I think.

@StefH commented on GitHub (Feb 20, 2020): Could be. Better code should be '.GetAwaiter().GetResult()' I think.
Author
Owner

@NoahLerner commented on GitHub (Feb 22, 2020):

Could be.
Better code should be '.GetAwaiter().GetResult()' I think.

Looks to me like best practice is using async await as apposed to GetAwaiter. Microsoft documentation indicates that GetAwaiter is not intended to be used in application code.

@NoahLerner commented on GitHub (Feb 22, 2020): > Could be. > Better code should be '.GetAwaiter().GetResult()' I think. Looks to me like best practice is using `async await` as apposed to `GetAwaiter`. Microsoft documentation indicates that `GetAwaiter` is not intended to be used in application code.
Author
Owner

@StefH commented on GitHub (Apr 3, 2020):

closing..

@StefH commented on GitHub (Apr 3, 2020): closing..
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#239