Closed abazanov closed 5 years ago
If I add this:
// Convert.ChangeType (below) chokes on Booleans, so doing it here instead.
if (propertyType == typeof(bool) || propertyType == typeof(bool?))
{
if (bool.TryParse(val.Value[0], out bool result))
{
return result;
}
return false;
}
Then it works.
We probably need to expand that out, Form binding wasn't really that well tested tbh. We may need to add TypeDescriptors instead. See here for example: https://www.hanselman.com/blog/TypeConvertersTheresNotEnoughTypeDescripterGetConverterInTheWorld.aspx
It then goes on to fail on DateTime?
and int?
😭
@jchannon do you think you will get some time to do that soon, or not really?
Potentially, if you need it sooner, feel free to take a crack at it :)
It is stopping me from progressing. If you can't do it in the next couple of days then I will have to give it a go. Do you think in the next couple of days is doable?
Probably not
Ok, let me have a quick look at the link you posted. Will get back to you. Cheers.
I am curious though how other people are using it currently ❓ Unless they do the binding themselves. 😕
Most I imagine are using JSON bodies not forms
On Mon, 8 Jul 2019 at 16:33, Andrei Bazanov notifications@github.com wrote:
I am curious though how other people are using it currently ❓ Unless they do the binding themselves. 😕
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/198?email_source=notifications&email_token=AAAZVJQLT2HESSH6SIABW63P6NM33A5CNFSM4H64L6X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZNO3AI#issuecomment-509275521, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZVJSO43CNAVZ4QR5CUIDP6NM33ANCNFSM4H64L6XQ .
Good point.
@jchannon I will give this a miss for now. I was using Postman which makes it very easy to fire forms at an API. With JSON, you have to type it all out. My assumption was that it would make no difference. Since it does, I will stop using forms. Thanks for your help.
I'll keep the issue open so it can be fixed at some point
For anyone wanting to pick this up the offending code sits in this block:
https://github.com/CarterCommunity/Carter/blob/master/src/ModelBinding/BindExtensions.cs#L48
If I was not running a bit late on this project, I would have. Maybe I will get some time, but for now, I don't, sorry.
Fails to bind a string to bool. Blows up with the error:
Invalid cast from 'System.String' to 'System.Nullable`1[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.