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

InvalidOperationException: Unable to resolve service for type 'AspNetCore.IpFiltering.IIpFilteringOptions' while attempting to activate 'AspNetCore.IpFiltering.IpFilteringMiddleware'. #1

Open
bor-man opened this issue Oct 21, 2022 · 1 comment

Comments

@bor-man
Copy link

bor-man commented Oct 21, 2022

I tried to run the samples from this repo or to install the Nuget and to call to all that you explained in the Read.me -always the same result - it pass build but when I execute the program: an error with this message:
InvalidOperationException: Unable to resolve service for type 'AspNetCore.IpFiltering.IIpFilteringOptions' while attempting to activate 'AspNetCore.IpFiltering.IpFilteringMiddleware'.

on line builder.Run(); of Main(string[] args) at Program.cs

Boris
[email protected]

@bor-man
Copy link
Author

bor-man commented Oct 24, 2022

Unbelievable... 2 days, hundreds of pages of information, and few unperfect workarounds later... I found the problem:

there is a bug in AspNetCore.IpFiltering/src/AspNetCore.IpFiltering/ServiceCollectionExtensions.cs
line 29: serviceCollection.AddSingleton /< IpFilteringOptions /> (options);

it should be :
serviceCollection.AddSingleton /< IIpFilteringOptions /> (options);
All other singletons are interfaces, only this one is a class. You can introduce it as a Scope (AddScope), but then it will not see the configurations from the appconfig. Adding this single "I" resolve the problem and samples also start to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant