Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WireMock.Net will not run with certain .net5 dependencies installed in the project #577

Closed
MikaelEliasson opened this issue Jan 30, 2021 · 14 comments
Labels

Comments

@MikaelEliasson
Copy link

Describe the bug

When running on .net 4.7.2 and with the Microsoft.Extensions.* packages being upgraded to 5.0.0.0 WireMock will crash on even the simplest calls.

The caller then gets the following 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.

Expected behavior:

I expect the call to go through and return the response.

Test to reproduce

Repro code: https://github.com/bokio/WireMockExperiment

The exceptions thrown is:

   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.CreateResponseHeader(Boolean appCompleted)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.InitializeResponseAsync(Int32 firstWriteByteCount)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WriteAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
   at WireMock.Owin.Mappers.OwinResponseMapper.<MapAsync>d__6.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at WireMock.Owin.WireMockMiddleware.<InvokeInternal>d__8.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at WireMock.Owin.GlobalExceptionMiddleware.<InvokeInternal>d__7.MoveNext()

You can see it if you put the breakpoint in https://github.com/bokio/WireMockExperiment/blob/master/Class1.cs#L55

I tested to install WireMock 1.4.2.0 in the 4.7.2 project without upgrading any libraries and then it worked. So it has to be one of the following dependencies. Because these were the ones we upgraded when we first saw the problem.

      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.8.1.0" newVersion="2.8.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Configuration.Binder" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Configuration.EnvironmentVariables" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="Microsoft.Extensions.Configuration.FileExtensions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.FileProviders.Physical" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>

Other related info

The test project is a simplification of what happened in our real project where we have Wiremock installed in .netstandard2.0 project and run the tests in 4.7.2. But as shown it becomes the same on 4.7.2.

@MikaelEliasson
Copy link
Author

I will try to nail down which of these dependencies that cause the issue. But if anyone have an idea it would be a welcome way to speed up the process.

@MikaelEliasson
Copy link
Author

Ok, updating Microsoft.Extensions.Configuration breaks WireMock. It pulls down these dependencies too:

image

@StefH
Copy link
Collaborator

StefH commented Jan 30, 2021

Do you have same issue with lower versions from Microsoft.Extensions?

@MikaelEliasson
Copy link
Author

No. I'm not sure exactly which version that introduce the issue but we were on 3.1.8.0 before we had to upgrade and then it worked. But considering 3.1.11.0 is the last version before 5.0.0.0 it seems likely it's 5.0.0.0 that cause the issue.

I just very confused to how it would cause a null ref in the kestrel pipeline. Is there any way to force WireMock to use the old Owin pipeline to see if it works better?

@StefH
Copy link
Collaborator

StefH commented Jan 30, 2021

I never tried using WireMock in .net 5.0

It could be that indeed some Owing pipeline functionality is changed / obsolete / broken.

@StefH StefH changed the title WireMock will not run with certain dependencies installed in the project WireMock.Net will not run with certain .net5 dependencies installed in the project Jan 31, 2021
@StefH
Copy link
Collaborator

StefH commented Jan 31, 2021

@MikaelEliasson

The root cause is likely related to this:
dotnet/aspnetcore#28112 (comment)

However, I could not find a way yet to fix this in WireMock.Net

Can't you move your unit test project to .net 5 or 3.1 ?

@MikaelEliasson
Copy link
Author

@StefH Going to 3.1 and then 5 is what we are doing and why we needed to upgrade those dependencies. The problem is that our project is a bit too large to update in one go so we need to take it in steps. And sadly this needs to be the next step.

Is it possible to force it using the old Owin host somehow? Otherwise we can probably fork the repo and hard code it to use that one while getting past this period.

@StefH
Copy link
Collaborator

StefH commented Feb 1, 2021

Hello @MikaelEliasson
If your unit test project is still 4.7.2, then also the version from WireMock.Net is matching that one (this will be the .NET 4.6.1 version)

Maybe adding a .NET 4.7.2 framework target to WireMock.Net could help using the correct OWIN implementation, I'll take a look tonight.

Another work-around is maybe adding manually a date header in the setup from the mapping.
Because if this code:
https://github.com/aspnet/KestrelHttpServer/blob/master/src/Kestrel.Core/Internal/Http/HttpProtocol.cs#L1190
Does not find a date-header, an then tries to call that InplaceStringBuilder which is removed in .net 50

@StefH
Copy link
Collaborator

StefH commented Feb 1, 2021

@MikaelEliasson

I've created a preview version on MyGet (WireMock.Net.1.4.2-ci-14604), can you try this one?

@xadvfh
Copy link

xadvfh commented Feb 2, 2021

I seem to be having a similar issue in dotnet core. I'm getting the following error when starting the server:

  Message: 
    System.MissingMethodException : Method not found: 'Microsoft.AspNetCore.Hosting.IWebHostBuilder Microsoft.AspNetCore.Hosting.IWebHostBuilder.ConfigureServices(System.Action`1<Microsoft.Extensions.DependencyInjection.IServiceCollection>)'.
  Stack Trace: 
    AspNetCoreSelfHost.StartAsync()
    WireMockServer.ctor(IWireMockServerSettings settings)
    WireMockServer.Start(Nullable`1 port, Boolean ssl)

My dotnet info:

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.102
 Commit:    71365b4d42

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.102\

Host (useful for support):
  Version: 5.0.2
  Commit:  cb5f173b96

.NET SDKs installed:
  3.1.405 [C:\Program Files\dotnet\sdk]
  5.0.101 [C:\Program Files\dotnet\sdk]
  5.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@xadvfh
Copy link

xadvfh commented Feb 2, 2021

@StefH I tried the latest 1.4.3-ci-14595 from myget and still face the same issue

@StefH
Copy link
Collaborator

StefH commented Feb 2, 2021

In my example project : https://github.com/WireMock-Net/WireMock.Net/tree/net5-issue/examples/WireMock.Net.Console.Net472.Classic adding a .net 5 nuget will work (that means that the "Date" issue is gone)

However this last issue seems be a different one.

Can you also create a example project for this please?

@xadvfh
Copy link

xadvfh commented Feb 2, 2021

@StefH it seems my issue is caused by nunit.engine package which might be overwriting a dependency that wiremock.net uses. When i uninstall the nunit.engine package it works

@StefH
Copy link
Collaborator

StefH commented Feb 2, 2021

#579

@StefH StefH closed this as completed Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants