3

If pass a byte array as parameter to a minimal api endpoint, like :

app.MapGet("api/srv/myget", [FromQuery] byte[] data) => DoSomethingWith(data);

then when I try tu run it throws an exception with:

No public static bool byte[].TryParse(string, out byte[]) method found for data.

For me is mandatory to keep the webservice's input format. Is there a way to do this with minimal API?

jeprato
  • 61
  • 1
  • 6
  • What it looks like in a plain text format? `https://host/api/srv/myget/......` https://stackoverflow.com/questions/23884182/how-to-get-byte-array-properly-from-an-web-api-method-in-c – McNets May 25 '22 at 12:25
  • When you say you need to keep the input form, are you referring to the HTTP request or to the method signature? If it's the former, you can replace data with HttpContext and access data with context.Request.Query["data"]. – Christof Wollenhaupt May 26 '22 at 09:49
  • 1
    When you specify FromQuery, you always end up in RequestDelegateFactory.BindParameterFromValue without a way to inject custom binders. The only known way for BindParametersFromValue to convert from a string is the static TryParse method. Static excludes extension methods. The fact we are talking about an array means we can't subclass. – Christof Wollenhaupt May 26 '22 at 10:10
  • Have you resolved this problem now? – Eniola Jul 02 '22 at 09:36
  • This is not supported but its unclear what you are trying to do from the question above. – davidfowl Aug 28 '22 at 18:47

0 Answers0