I have the following query parameter struct for my Minimal API endpoint (simplified for this example):
public struct QueryParameters
{
public Dictionary<string, string>? Filters { get; init; }
}
My endpoint is defined like (simplified for this example):
public async ValueTask<IResult> GetAllAsync([AsParameters] QueryParameters queryParameters)
{
return TypedResults.Ok();
}
When I try to start my Minimal API, dotnet throws the following error:
Unhandled exception. System.InvalidOperationException: Filters must have a valid TryParse method to support converting from a string. No public static bool Dictionary<string, string>.TryParse(string, out Dictionary<string, string>) method found for Filters.
Looking at a few resources, I have the impression that potentially there’s no out-of-the-box model binding for dictionaries in net8 Minimal APIs.
I have tried adding a an extension method to Dictionary<string, string> for the TryParse
, but couldn’t get that path to work (kept seeing the same error).
How do I solve this problem?