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

TypeLoadException when using WithHeader method. #928

Closed
eshref opened this issue May 4, 2023 · 19 comments
Closed

TypeLoadException when using WithHeader method. #928

eshref opened this issue May 4, 2023 · 19 comments
Assignees
Labels

Comments

@eshref
Copy link

eshref commented May 4, 2023

Hi, friends.

I am getting

System.TypeLoadException
Could not load type 'FluentAssertions.Collections.SelfReferencingCollectionAssertions`2' from assembly 'FluentAssertions, Version=6.6.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a'.
   at WireMock.FluentAssertions.WireMockAssertions.WithHeader(String expectedKey, String[] expectedValues, String because, Object[] becauseArgs)

error when I use below assertion code in my test which is net472 project.

_wireMockServer
                .Should()
                .HaveReceivedACall()
                .AtAbsoluteUrl("some-url").And
                .WithHeader("header-name", "header-value");

I am using below versions of packages in test project.

image

Any help is appreciated.

@StefH StefH self-assigned this May 12, 2023
@StefH
Copy link
Collaborator

StefH commented May 12, 2023

Can you please provide the full project ?

@StefH
Copy link
Collaborator

StefH commented May 31, 2023

@eshref
Can you please provide a full project with this error?

@eshref
Copy link
Author

eshref commented Jun 1, 2023

Hi, @StefH. Sorry for late response.

Here is my csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <NoWarn>0067</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="WireMock.Net" Version="1.5.13" />
    <PackageReference Include="FluentAssertions" Version="6.6.0" />
    <PackageReference Include="WireMock.Net.FluentAssertions" Version="1.5.13" />
        <PackageReference Include="WireMock.Net.FluentAssertions" Version="1.5.13" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.2.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

And this is test class:

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

using FluentAssertions;

using WireMock.FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;

using Xunit;


namespace TestProject1
{
    public class UnitTest1 : IDisposable
    {
        private readonly WireMockServer _wireMockServer;


        public UnitTest1()
        {
            _wireMockServer = WireMockServer.Start(8081);
        }


        public void Dispose()
        {
            _wireMockServer.Stop();
            _wireMockServer.Dispose();
        }


        [Fact]
        public async Task Test1()
        {
            // arrange
            var httpClient = new HttpClient();

            _wireMockServer.Given(
                    Request.Create()
                        .WithPath("/someurl")
                        .UsingPost())
                .RespondWith(
                    Response.Create()
                        .WithStatusCode(HttpStatusCode.OK));

            // act
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8081/someurl")
            {
                Headers =
                {
                    { "header-name", "header-value" }
                }
            };

            HttpResponseMessage response = await httpClient.SendAsync(httpRequestMessage);

            // assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            _wireMockServer
                .Should()
                .HaveReceivedACall()
                .AtAbsoluteUrl("http://localhost:8081/someurl").And
                .WithHeader("header-name", "header-value");
        }
    }
}

@StefH StefH added the question label Jun 1, 2023
@StefH
Copy link
Collaborator

StefH commented Jun 1, 2023

Using your slightly modified csproj and the same test file it works fine in VS2022.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net472</TargetFramework>
        <NoWarn>0067</NoWarn>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="WireMock.Net" Version="1.5.13" />
        <PackageReference Include="WireMock.Net.FluentAssertions" Version="1.5.13" />
        <PackageReference Include="xunit" Version="2.4.2" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
        <PackageReference Include="coverlet.collector" Version="3.2.0">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
    </ItemGroup>

</Project>

image

@StefH StefH closed this as completed Jun 1, 2023
@eshref
Copy link
Author

eshref commented Jun 1, 2023

Why you removed FluentAssertions 6.6.0? We use this version of FA package.

@StefH
Copy link
Collaborator

StefH commented Jun 1, 2023

Ah I see. That causes probably the issue.

Version 5 and 6 from FluentAssertions are not compatible.

The only thing what can be done is that I create 2 packages for WireMock.Net.FluentAssertions, one with 5 and one with 6.

@eshref
Copy link
Author

eshref commented Jun 1, 2023

Wouldn't it be better to to upgrade FA dependency and release new breaking change instead of supporting two packages?

@StefH
Copy link
Collaborator

StefH commented Jun 1, 2023

The issue is that version 6 is not supported by lower frameworks. But I can make a workaround for that I think.

@StefH
Copy link
Collaborator

StefH commented Jun 1, 2023

Can you try preview version 1.5.26-ci-17452 ?

@eshref
Copy link
Author

eshref commented Jun 2, 2023

Did you push this version to nuget? I am getting below warnings after manually updating versions:

warning NU1603: TestProject1 depends on WireMock.Net (>= 1.5.26-ci-17452) but WireMock.Net 1.5.26-ci-17452 was not found. An approximate best match of WireMock.Net 1.5.26 was resolved.
warning NU1603: TestProject1 depends on WireMock.Net.FluentAssertions (>= 1.5.26-ci-17452) but WireMock.Net.FluentAssertions 1.5.26-ci-17452 was not found. An approximate best match of WireMock.Net.FluentAssertions 1.5.26 was resolved.

@StefH
Copy link
Collaborator

StefH commented Jun 2, 2023

@eshref
Copy link
Author

eshref commented Jun 2, 2023

Added this package and run test, same problem occured.

@StefH
Copy link
Collaborator

StefH commented Jun 2, 2023

Can you try
1.5.26-ci-17457

@eshref
Copy link
Author

eshref commented Jun 2, 2023

This one worked, thanks. 🙏🏼

@eshref
Copy link
Author

eshref commented Jun 2, 2023

I would be glad, if you share solution :)

@StefH
Copy link
Collaborator

StefH commented Jun 2, 2023

I would be glad, if you share solution :)

You mean a new official NuGet ?

@eshref
Copy link
Author

eshref commented Jun 2, 2023

I would be glad, if you share solution :)

You mean a new official NuGet ?

Yes, but also I meant what changes did you do in this myget package? Only above changes (#949)

@StefH
Copy link
Collaborator

StefH commented Jun 2, 2023

That commit was actually not correct.

I did a commit op master which solved it.

@eshref
Copy link
Author

eshref commented Jun 2, 2023

Thanks for your quick help.

@StefH StefH closed this as completed Jun 3, 2023
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

2 participants