WireMock.Net is throwing an exception: "An error occurred while sending the request"

1 day ago 1
ARTICLE AD BOX

WireMock.Net seems to be incompatible with Microsoft.Owin.Security.Interop.

Consider the following .csproj file:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net48</TargetFramework> <LangVersion>latest</LangVersion> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" /> <PackageReference Include="Microsoft.Owin.Security.Interop" Version="2.3.9" /> <PackageReference Include="NUnit" Version="4.4.0" /> <PackageReference Include="NUnit3TestAdapter" Version="6.1.0" /> <PackageReference Include="WireMock.Net" Version="1.25.0" /> </ItemGroup> <ItemGroup> <Using Include="NUnit.Framework" /> </ItemGroup> </Project>

And consider this test:

using System.Net; using System.Net.Http; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; using WireMock.Server; namespace WireMockTester; public class WireMockTest { [Test] public async Task PostRequestUsingHttpClient() { var wmServer = WireMockServer.Start(); wmServer .Given(Request.Create().UsingPost()) .RespondWith(Response.Create().WithStatusCode(200)); using var httpClient = new HttpClient(); using var content = new StringContent("Post Content"); using var response = await httpClient.PostAsync(new Uri(wmServer.Url!), content); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); } }

The test will throw this exception:

System.Net.Http.HttpRequestException : An error occurred while sending the request.
System.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly.

If I remove Microsoft.Owin.Security.Interop as a package reference, the test will pass. However this isn't an option for me because our actual SUT is a .NET 4.8 website that uses this package.

Why does Microsoft.Owin.Security.Interop cause WireMock to fail and how can I fix this?

marc_s's user avatar

marc_s

760k186 gold badges1.4k silver badges1.5k bronze badges

isxpjm's user avatar

4

Read Entire Article