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

FromQuery Error: InvalidOperationException: No public static bool GenericFilter.TryParse(string, out GenericFilter) method found for filter. #57

Open
gpproton opened this issue Jan 7, 2023 · 5 comments
Labels
question Further information is requested

Comments

@gpproton
Copy link

gpproton commented Jan 7, 2023

I'm Currently trying out AutoFilterer and it works well with using FromBody but not with FromQuery

Below are the full error message generated, i'm sticking to using FromBody for not just wanted to report the issue.

Microsoft.AspNetCore.Http.RequestDelegateFactory.BindParameterFromValue(ParameterInfo parameter, Expression valueExpression, RequestDelegateFactoryContext factoryContext, string source)
Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgument(ParameterInfo parameter, RequestDelegateFactoryContext factoryContext)
Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArguments(ParameterInfo[] parameters, RequestDelegateFactoryContext factoryContext)
Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgumentsAndInferMetadata(MethodInfo methodInfo, RequestDelegateFactoryContext factoryContext)
Microsoft.AspNetCore.Http.RequestDelegateFactory.InferMetadata(MethodInfo methodInfo, RequestDelegateFactoryOptions options)
Microsoft.AspNetCore.Routing.RouteEndpointDataSource.CreateRouteEndpointBuilder(RouteEntry entry, RoutePattern groupPrefix, IReadOnlyList<Action> groupConventions, IReadOnlyList<Action> groupFinallyConventions)
Microsoft.AspNetCore.Routing.RouteEndpointDataSource.GetGroupedEndpoints(RouteGroupContext context)
Microsoft.AspNetCore.Routing.RouteGroupBuilder+GroupEndpointDataSource.GetGroupedEndpointsWithNullablePrefix(RoutePattern prefix, IReadOnlyList<Action> conventions, IReadOnlyList<Action> finallyConventions, IServiceProvider applicationServices)
Microsoft.AspNetCore.Routing.RouteGroupBuilder+GroupEndpointDataSource.get_Endpoints()
Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.CreateEndpointsUnsynchronized()
Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.EnsureEndpointsInitialized()
Microsoft.AspNetCore.Routing.DataSourceDependentCache.Initialize()
System.Threading.LazyInitializer.EnsureInitializedCore(ref T target, ref bool initialized, ref object syncLock, Func valueFactory)
Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func matcherBuilderFactory)
Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatcher|8_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matcherTask)
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

@enisn
Copy link
Owner

enisn commented Jan 7, 2023

It seems it's an AspNetCore binding error. Your value might have some special characters or something that can break the binding

@gpproton
Copy link
Author

gpproton commented Jan 8, 2023

I thought so initially, below is the sample filter used.

// Sample filter
public class GenericFilter : PaginationFilterBase{ }

// Sample DTO
public class SampleDto : FilterBase {
public Guid Id { get; set; }
public string Name { get; set; }
}

@enisn
Copy link
Owner

enisn commented Jan 8, 2023

I understand the problem but nothing to do in autofilterer library. Autofilterer generates only LINQ expressions and it doesn't know about your aspnetcore application or how to bind object properties.

There is no aspnetcore dependency of autofilterer.

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageTags>netstandard, EntityFramework, netcore, aspnetcore, auto filter, filtering, sorting, ordering, pagination</PackageTags>
<PackageIconUrl />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>C:\Users\enisn\source\repos\enisn\AutoFilterer\src\AutoFilterer\AutoFilterer.xml</DocumentationFile>
<NoWarn>1701;1702;CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

You may ask your question at dotnet/aspnetcore repositroy

@gpproton
Copy link
Author

gpproton commented Jan 8, 2023

I was able to use fine on dotnet 7 with the new AsParameters which is better for minimal API

Here

group.MapGet("/", async ([FromServices] CategoryService sv, [AsParameters] CategoryFilter filter) => await sv.GetAllAsync(filter))
            .WithName($"GetAll{name}")
            .WithOpenApi();

@enisn
Copy link
Owner

enisn commented Jan 8, 2023

@enisn enisn added the question Further information is requested label Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants