Cannot create instance of FluentMockServer without running .Start() #255

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

Originally created by @TheLordDrake on GitHub (Feb 25, 2020).

When attempting to new up an instance of FluentMockServer and passing a FluentMockServerSettings instance it encounter the following error:
image
(Argument type 'WireMock.Settings.FluentMockServerSettings' is not assignable to parameter type 'WireMock.Settings.IFluentMockServerSettings')

On inspection FluentMockServer has a constructor that takes IFluentMockServerSettings and calls its base with a cast to IWireMockServerSettings.

public class FluentMockServer : WireMockServer
{
  public FluentMockServer(IFluentMockServerSettings settings)
    : base((IWireMockServerSettings) settings)
  {
  }
}

IFluentMockServerSettings is an empty wrapper around IWireMockServerSettings.

public interface IFluentMockServerSettings : IWireMockServerSettings
{
}

As a work around I tried newing up an instance of WireMockServer directly, and found I was unable to do so as it has a protected contructor.
image
(Cannot access protected constructor 'WireMockServer' here)

protected WireMockServer(IWireMockServerSettings settings)
{
*snip*
}

To me this appears to be a bug, with possible fixes including removing the protected scope of the WireMockServer constructor, or resolving the issue with FluentMockServerSettings being an invalid type. I was going to create a PR to resolve this, but when I forked and cloned the repo I discovered that it has numerous build errors, several of which I'm uncertain how to resolve at the moment.

Originally created by @TheLordDrake on GitHub (Feb 25, 2020). When attempting to new up an instance of `FluentMockServer` and passing a `FluentMockServerSettings` instance it encounter the following error: ![image](https://user-images.githubusercontent.com/24683014/75269833-8e8dfd80-57c7-11ea-84e6-f3371189b80a.png) _(Argument type 'WireMock.Settings.FluentMockServerSettings' is not assignable to parameter type 'WireMock.Settings.IFluentMockServerSettings')_ On inspection `FluentMockServer` has a constructor that takes `IFluentMockServerSettings` and calls its `base` with a cast to `IWireMockServerSettings`. ```C# public class FluentMockServer : WireMockServer { public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings) { } } ``` `IFluentMockServerSettings` is an empty wrapper around `IWireMockServerSettings`. ```C# public interface IFluentMockServerSettings : IWireMockServerSettings { } ``` As a work around I tried newing up an instance of `WireMockServer` directly, and found I was unable to do so as it has a `protected` contructor. ![image](https://user-images.githubusercontent.com/24683014/75270760-188a9600-57c9-11ea-806d-a75b4bcd79c5.png) _(Cannot access protected constructor 'WireMockServer' here)_ ```C# protected WireMockServer(IWireMockServerSettings settings) { *snip* } ``` To me this appears to be a bug, with possible fixes including removing the `protected` scope of the `WireMockServer` constructor, or resolving the issue with `FluentMockServerSettings` being an invalid type. I was going to create a PR to resolve this, but when I forked and cloned the repo I discovered that it has numerous build errors, several of which I'm uncertain how to resolve at the moment.
adam added the question label 2025-12-29 15:19:08 +01:00
adam closed this issue 2025-12-29 15:19:08 +01:00
Author
Owner

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

Just use WireMockServer.Start

var server = WireMockServer.Start(new FluentMockServerSettings
{
    Urls = new[] { "http://localhost:9095/" },
    StartAdminInterface = true,
    ProxyAndRecordSettings = new ProxyAndRecordSettings
    {
        Url = "http://www.bbc.com",
        SaveMapping = true,
        SaveMappingToFile = true,
        BlackListedHeaders = new [] { "dnt", "Content-Length" },
        BlackListedCookies = new [] { "c1", "c2" },
        SaveMappingForStatusCodePattern = "2xx",
        AllowAutoRedirect = true,
        WebProxySettings = new WebProxySettings
        {
            UserName = "test",
            Password = "pwd",
            Address = "http://company.proxy"
        }
    }
});

The FluentMockServer is obsolete (however it should more or less still work...)

@StefH commented on GitHub (Feb 25, 2020): Just use `WireMockServer.Start` ``` c# var server = WireMockServer.Start(new FluentMockServerSettings { Urls = new[] { "http://localhost:9095/" }, StartAdminInterface = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://www.bbc.com", SaveMapping = true, SaveMappingToFile = true, BlackListedHeaders = new [] { "dnt", "Content-Length" }, BlackListedCookies = new [] { "c1", "c2" }, SaveMappingForStatusCodePattern = "2xx", AllowAutoRedirect = true, WebProxySettings = new WebProxySettings { UserName = "test", Password = "pwd", Address = "http://company.proxy" } } }); ``` The **FluentMockServer** is obsolete (however it should more or less still work...)
Author
Owner

@TheLordDrake commented on GitHub (Feb 25, 2020):

I was trying to avoid that, but I've since moved on from that approach, so .Start() does bypass this issue.
Would a more appropriate resolution be to remove FluentMockServer and IFluentMockServer or at least mark them as deprecated?

@TheLordDrake commented on GitHub (Feb 25, 2020): I was trying to avoid that, but I've since moved on from that approach, so `.Start()` does bypass this issue. Would a more appropriate resolution be to remove `FluentMockServer` and `IFluentMockServer` or at least mark them as deprecated?
Author
Owner

@StefH commented on GitHub (Mar 5, 2020):

I'll mark FluentMockServer + FluentMockServerSettings obsolete in one of the next releases.

@StefH commented on GitHub (Mar 5, 2020): I'll mark FluentMockServer + FluentMockServerSettings obsolete in one of the next releases.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#255