-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
TaskResultConverter causes an InvalidCastException (can't cast COM object to T) #4505
Comments
@Sergio0694 this was done in #3960 to fix #3311 as the docs guidance is to return UnsetValue instead of null. |
More detailed docs on this issue: Exceptions from converters. @Sergio0694 Do you have an updated link to a working repro? I'd like to take a look. |
@Arlodotexe It's no longer crashing in the sample app because I used a temporary converter as a workaround, see CommunityToolkit/MVVM-Samples@0138b7a. If you remove it you can then repro the crash there as well. Imho we should just change this back to returning |
@Sergio0694 I think what the docs and we're trying to say is the binding should be this: <Run Text="{x:Bind ViewModel.DownloadTextCommand.ExecutionTask, Converter={StaticResource TaskResultConverter}, FallbackValue='Task not set', Mode=OneWay}" />
As passing |
Wouldn't that apply to an actual dependency property though? In this case it's just a converter. It's receiving a value that has no result, so it's giving you back I've always treated the fallback path to be someting to use if the actual path is not valid, eg. if you have a complex path and some item along the way is |
Hmm, was just looking at our existing tests here: WindowsCommunityToolkit/UnitTests/UnitTests.UWP/Converters/Test_TaskResultConverter.cs Lines 72 to 103 in b2b1c23
If any task is bound, it should return null if there is no result, so I'm confused now. Let me pull down the MVVM Sample app and try and get a repro there to better understand what's happening. |
I tested this out directly in the MVVM Sample App and I understand now where @Sergio0694 and I were disconnecting. The MVVM Toolkit's This means the binding in the app was pointing to a Basically, regardless of if we have a
This doesn't define the behavior if the input |
…fault value in case task is not set or has not completed. Updated description to include unset Task scenario (i.e. null being passed in) Updated to include proper default value return for Value types Included value passthru for non-Task values
…fault value in case task is not set or has not completed. Updated description to include unset Task scenario (i.e. null being passed in) Updated to include proper default value return for Value types Included value passthru for non-Task values
Describe the bug
The
TaskResultConverter
returnsDependencyProperty.UnsetValue
in the fallback path.This causes invalid cast exceptions downstream when trying to convert the object to some type.
The converter should just return
null
if no value is available.Regression
No, always been like this.
Reproducible in sample app?
Steps to reproduce
Expected behavior
The converter should return
null
.Screenshots
Help us help you
Yes, I'd like to be assigned to work on this item.
The text was updated successfully, but these errors were encountered: