How to load 'ProxyAndRecordSettings' from 'appsettings.json' ? #409

Closed
opened 2025-12-29 15:23:02 +01:00 by adam · 13 comments
Owner

Originally created by @PrzemekScott on GitHub (Mar 9, 2022).

I've experimented with WM stand alone version locally, with such settings:

image

Now wanted to experiment with WM as web app and then set it on Azure, but not sure how to implement 'ProxyAndRecordSetting' in appsettings file. When I have it like below:
image

I'm getting such error:

System.InvalidOperationException: Cannot create instance of type 'WireMock.Settings.IProxyAndRecordSettings' because it is either abstract or an interface.

The way I run WM with configuration is from one of 'examples projects' :
image

thx

Originally created by @PrzemekScott on GitHub (Mar 9, 2022). I've experimented with WM stand alone version locally, with such settings: ![image](https://user-images.githubusercontent.com/88881374/157453286-17eb7542-3862-4950-86fa-14dd0decdaba.png) Now wanted to experiment with WM as web app and then set it on Azure, but not sure how to implement 'ProxyAndRecordSetting' in appsettings file. When I have it like below: ![image](https://user-images.githubusercontent.com/88881374/157453453-8d5ea461-eb44-429d-bc40-0c17cda271ae.png) I'm getting such error: ` System.InvalidOperationException: Cannot create instance of type 'WireMock.Settings.IProxyAndRecordSettings' because it is either abstract or an interface.` The way I run WM with configuration is from one of 'examples projects' : ![image](https://user-images.githubusercontent.com/88881374/157453657-6e92e68a-360c-4d64-b63e-9fa6ba1f71a7.png) thx
adam added the question label 2025-12-29 15:23:02 +01:00
adam closed this issue 2025-12-29 15:23:03 +01:00
Author
Owner

@StefH commented on GitHub (Mar 9, 2022):

@PrzemekScott
I don't think this is possible.

I'll investigate why I decided to use an interface instead of a class, and see if I can remove the interface.

@StefH commented on GitHub (Mar 9, 2022): @PrzemekScott I don't think this is possible. - https://stackoverflow.com/questions/70830418/configuration-interface-inside-an-inteface-in-appsettings-json - https://stackoverflow.com/questions/59124184/options-pattern-interface-abstract-property I'll investigate why I decided to use an interface instead of a class, and see if I can remove the interface.
Author
Owner

@PrzemekScott commented on GitHub (Mar 9, 2022):

I see.
Is then any other way to run WM on Azure in "proxying mode" (when needed - less often) and in "matching mode" (when needed - most of the time) ?

@PrzemekScott commented on GitHub (Mar 9, 2022): I see. Is then any other way to run WM on Azure in "proxying mode" (when needed - less often) and in "matching mode" (when needed - most of the time) ?
Author
Owner

@StefH commented on GitHub (Mar 9, 2022):

Only workaround for now is to split the settings in two sections:

"WireMockServerSettings": {
},
"ProxyAndRecordSettings": {
}

And then do two calls:

  1. GetSection as you have now on WireMockServerSettings
  2. GetSection on ProxyAndRecordSettings
  3. Combine the outcome from step 2 in the resolved object from step 1
@StefH commented on GitHub (Mar 9, 2022): Only workaround for now is to split the settings in two sections: ``` json "WireMockServerSettings": { }, "ProxyAndRecordSettings": { } ``` And then do two calls: 1. GetSection as you have now on WireMockServerSettings 2. GetSection on ProxyAndRecordSettings 3. Combine the outcome from step 2 in the resolved object from step 1
Author
Owner

@StefH commented on GitHub (Mar 9, 2022):

@PrzemekScott

I've created a preview version which only has classes for settings; no interfaces anymore.

Preview version = 1.4.37-ci-15956.

See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

https://github.com/WireMock-Net/WireMock.Net/pull/736

@StefH commented on GitHub (Mar 9, 2022): @PrzemekScott I've created a preview version which only has classes for settings; no interfaces anymore. Preview version = `1.4.37-ci-15956`. See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions https://github.com/WireMock-Net/WireMock.Net/pull/736
Author
Owner

@PrzemekScott commented on GitHub (Mar 10, 2022):

Thanks @StefH. Will give it a try.

@PrzemekScott commented on GitHub (Mar 10, 2022): Thanks @StefH. Will give it a try.
Author
Owner

@PrzemekScott commented on GitHub (Mar 10, 2022):

@StefH ,
Thanks for that change. It works well, starting server with all settings from the appsettings.json file"

image

Yet, there is one thing which I do not understand.
When I Run the App - I'm using JB Rider as my IDE - in next several seconds the browser is opened with this url as below:

image

@PrzemekScott commented on GitHub (Mar 10, 2022): @StefH , Thanks for that change. It works well, starting server with all settings from the appsettings.json file" ![image](https://user-images.githubusercontent.com/88881374/157655323-f2b7369c-08a5-49e3-af89-347cf4248cd4.png) Yet, there is one thing which I do not understand. When I Run the App - I'm using JB Rider as my IDE - in next several seconds the browser is opened with this url as below: ![image](https://user-images.githubusercontent.com/88881374/157655727-e6cd1f0f-3e10-4c58-a4f6-002be13b440a.png)
Author
Owner

@StefH commented on GitHub (Mar 10, 2022):

Can you provide your full project?

@StefH commented on GitHub (Mar 10, 2022): Can you provide your full project?
Author
Owner

@PrzemekScott commented on GitHub (Mar 10, 2022):

Unfortunately @StefH, I've started WM project as a POC under one of test automation projects in my organisation and all of such projects are set as 'Internal', it is also bonded with our internal tools, accesses, so, unfortunately I can't share it.

What we’ve checked is that colleagues working with Visual Studio IDE are not facing this “action” of opening browser when ‘Program’ is run - it's only happening when "Program" is run in my JB Rider (on macOS).

image

image

@PrzemekScott commented on GitHub (Mar 10, 2022): Unfortunately @StefH, I've started WM project as a POC under one of test automation projects in my organisation and all of such projects are set as 'Internal', it is also bonded with our internal tools, accesses, so, unfortunately I can't share it. What we’ve checked is that colleagues working with Visual Studio IDE are not facing this “action” of opening browser when ‘Program’ is run - it's only happening when "Program" is run in my JB Rider (on macOS). ![image](https://user-images.githubusercontent.com/88881374/157744882-63c18ffd-b809-4eb0-8ef3-1b7892145a69.png) ![image](https://user-images.githubusercontent.com/88881374/157744940-d98cfc8d-453d-4516-9f79-0e4c636c97b8.png)
Author
Owner

@StefH commented on GitHub (Mar 10, 2022):

Can you share your appsettings.json and the startup code?

From that I can try to reproduce it

@StefH commented on GitHub (Mar 10, 2022): Can you share your appsettings.json and the startup code? From that I can try to reproduce it
Author
Owner

@PrzemekScott commented on GitHub (Mar 11, 2022):

Sure I can share files.
Archive.zip

@PrzemekScott commented on GitHub (Mar 11, 2022): Sure I can share files. [Archive.zip](https://github.com/WireMock-Net/WireMock.Net/files/8230531/Archive.zip)
Author
Owner

@StefH commented on GitHub (Mar 11, 2022):

When running as:
image

It just works fine?
image

@StefH commented on GitHub (Mar 11, 2022): When running as: ![image](https://user-images.githubusercontent.com/249938/157838943-7ef72905-e985-40cf-9785-8c63f0cbb734.png) It just works fine? ![image](https://user-images.githubusercontent.com/249938/157838908-c6e77aea-7df6-4bcd-8e54-8c15cb795dcb.png)
Author
Owner

@PrzemekScott commented on GitHub (Mar 11, 2022):

So as it also did for my colleagues using Visual Studio. I will try to contact Jet Brain and as for some support. Maybe, just an assumption, that when JB Rider is Run(ning) web app type App, it opens it on some predefined port. But I couldn't find it in settings.

Anyway, thank you StefH for help and changing interface to class in appsettings. I think we can consider this Question as closed.

@PrzemekScott commented on GitHub (Mar 11, 2022): So as it also did for my colleagues using Visual Studio. I will try to contact Jet Brain and as for some support. Maybe, just an assumption, that when JB Rider is Run(ning) web app type App, it opens it on some predefined port. But I couldn't find it in settings. Anyway, thank you StefH for help and changing interface to class in appsettings. I think we can consider this Question as closed.
Author
Owner

@PrzemekScott commented on GitHub (Mar 11, 2022):

;) actually I've just found it in launchSettings:

image

image

launchSettings json
@PrzemekScott commented on GitHub (Mar 11, 2022): ;) actually I've just found it in launchSettings: ![image](https://user-images.githubusercontent.com/88881374/157858145-49c42ad1-0deb-4de7-9635-2046cc36e521.png) ![image](https://user-images.githubusercontent.com/88881374/157858228-4a7b42da-3f54-4f82-85f4-0b04de4557dd.png) <img width="1342" alt="launchSettings json" src="https://user-images.githubusercontent.com/88881374/157858810-81f1ffe0-95ca-4ba1-916c-188054dd93b4.png">
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#409