Wiremock not working with NUnit3 in .Net Framework 4.6.1 after Wiremock 1.5.47 #591

Closed
opened 2025-12-29 15:27:49 +01:00 by adam · 3 comments
Owner

Originally created by @MarcoMartins86 on GitHub (Apr 2, 2024).

Describe the bug

I've made a clean project with only

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NUnit" Version="3.14.0" />
    <PackageReference Include="WireMock.Net.StandAlone" Version="1.5.47" />
  </ItemGroup>
</Project>
[TestFixture]
public class TestingWiremock
{
    private WireMockServer _server;
    [SetUp]
    protected async Task Setup()
    {
        _server = StandAloneApp.Start(new WireMockServerSettings());
        _server
            .Given(Request.Create().UsingGet())
            .RespondWith(Response.Create());
        await Task.Delay(2000);
    }

    [Test]
    public void Test()
    {
        var client = new HttpClient();
        var result = client.GetAsync(_server.Url).Result;
        Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK)); // test will timeout in 1.5.47+, pass on 1.5.46
    }
}

The behavior I've got is similar to the one described on this other thread https://github.com/WireMock-Net/WireMock.Net/issues/470, there's no error and it seems to be on some kind of deadlock somewhere but I can't pinpoint it.

Expected behavior:

Should work with .Net Framework 4.6.1 and NUnit3

Test to reproduce

  • 1: Run the fixture

With Wiremock version 1.5.46 it is working.
Also, it is working with .Net Framework 4.6.2 for 1.5.47+
Workaround, stay on 1.5.46 for now.

Originally created by @MarcoMartins86 on GitHub (Apr 2, 2024). ### Describe the bug I've made a clean project with only ``` <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net461</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="NUnit" Version="3.14.0" /> <PackageReference Include="WireMock.Net.StandAlone" Version="1.5.47" /> </ItemGroup> </Project> ``` ``` C# [TestFixture] public class TestingWiremock { private WireMockServer _server; [SetUp] protected async Task Setup() { _server = StandAloneApp.Start(new WireMockServerSettings()); _server .Given(Request.Create().UsingGet()) .RespondWith(Response.Create()); await Task.Delay(2000); } [Test] public void Test() { var client = new HttpClient(); var result = client.GetAsync(_server.Url).Result; Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK)); // test will timeout in 1.5.47+, pass on 1.5.46 } } ``` The behavior I've got is similar to the one described on this other thread https://github.com/WireMock-Net/WireMock.Net/issues/470, there's no error and it seems to be on some kind of deadlock somewhere but I can't pinpoint it. ### Expected behavior: Should work with .Net Framework 4.6.1 and NUnit3 ### Test to reproduce - 1: Run the fixture ### Other related info With Wiremock version 1.5.46 it is working. Also, it is working with .Net Framework 4.6.2 for 1.5.47+ Workaround, stay on 1.5.46 for now.
adam added the invalid label 2025-12-29 15:27:49 +01:00
adam closed this issue 2025-12-29 15:27:50 +01:00
Author
Owner

@StefH commented on GitHub (Apr 2, 2024):

@MarcoMartins86
Did you try to make the test async?
Like:

[Test]
    public async Task Test()
    {
        var client = new HttpClient();
        var result = await client.GetAsync(_server.Url);
        Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
    }
@StefH commented on GitHub (Apr 2, 2024): @MarcoMartins86 Did you try to make the test async? Like: ``` c# [Test] public async Task Test() { var client = new HttpClient(); var result = await client.GetAsync(_server.Url); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK)); } ```
Author
Owner

@MarcoMartins86 commented on GitHub (Apr 2, 2024):

@StefH Fail with the same behavior.

System.Net.Http.HttpRequestException : An error occurred while sending the request.
  ----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive.
  ----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
  ----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Adding a logger I can see that the server prints Server listening at http://localhost:57550 but then no request reachs the WireMockMiddleware.Invoke() (reach when working). Feels like the server have a deadlock somewhere at the beginning of request pipeline, because, it reserved the port successfully since if I try to reuse the same port while the process is running it says it is already in use.

@MarcoMartins86 commented on GitHub (Apr 2, 2024): @StefH Fail with the same behavior. ```` System.Net.Http.HttpRequestException : An error occurred while sending the request. ----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive. ----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) ```` Adding a logger I can see that the server prints `Server listening at http://localhost:57550` but then no request reachs the `WireMockMiddleware.Invoke()` (reach when working). Feels like the server have a deadlock somewhere at the beginning of request pipeline, because, it reserved the port successfully since if I try to reuse the same port while the process is running it says it is already in use.
Author
Owner

@MarcoMartins86 commented on GitHub (Apr 3, 2024):

I will close this, I've added <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> and it started working for all versions. For me, that is good enough.
Thank you for your time and good work.

@MarcoMartins86 commented on GitHub (Apr 3, 2024): I will close this, I've added `<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />` and it started working for all versions. For me, that is good enough. Thank you for your time and good work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#591