You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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.
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]
The text was updated successfully, but these errors were encountered: