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

Error handling is different for compiled bindings #22078

Open
DarkStarDS9 opened this issue Apr 26, 2024 · 4 comments
Open

Error handling is different for compiled bindings #22078

DarkStarDS9 opened this issue Apr 26, 2024 · 4 comments
Labels
area-xaml XAML, CSS, Triggers, Behaviors s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@DarkStarDS9
Copy link

DarkStarDS9 commented Apr 26, 2024

Description

When the getter of a property throws a NullReferenceException, this will be caught and silently ignored for compiled bindings, there won't even be a diagnostic-log via BindingDiagnostics.SendBindingFailure.

Binding expressions however execute the getter without any try/catch and will therefore throw.

If this difference in error-handling is on purpose, I'd ask to document this on the "Compiled bindings" page and add some logging via BindingDiagnostics.SendBindingFailure.

I'd prefer to have the behavior aligned either way, but if it is decided that it should not throw, I would really like to see some logging so that this can be caught in a UnitTest, for example.

Steps to Reproduce

No response

Link to public reproduction project repository

https://github.com/DarkStarDS9/MauiIssues

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@DarkStarDS9 DarkStarDS9 added the t/bug Something isn't working label Apr 26, 2024
@PureWeen PureWeen added area-xaml XAML, CSS, Triggers, Behaviors s/needs-repro Attach a solution or code which reproduces the issue labels Apr 26, 2024
@DarkStarDS9
Copy link
Author

I've updated the description to point to my repo. If you run the UnitTests in Debug configuration, they will fail because a NullReferenceException is thrown. If you run the UnitTests in Release configuration they will fail because the exception will be swallowed and no BindingError will be logged.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Apr 28, 2024
@kevinxufei
Copy link
Collaborator

Verified this issue with Visual Studio 17.10 Preview 5 (8.0.21). Can not repro issue with sample project.

@kevinxufei kevinxufei added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Apr 29, 2024
@DarkStarDS9
Copy link
Author

I have updated the repo to .21 (sorry, didn't check this before - kinda assumed that dotnet new will create a project using the most recent version). Strangely I also had to adjust the test and add yet another mock... but anyway, the issue is still there.

BTW, I am not running this in Visual Studio but from the command-line:

dotnet test -c Debug
[xUnit.net 00:00:00.28] UnitTests.Issue22078Tests.SetBindingContext [FAIL] Failed UnitTests.Issue22078Tests.SetBindingContext [189 ms] Error Message: System.NullReferenceException : Object reference not set to an instance of an object. Stack Trace: at MauiIssues.Issue22078ViewModel.get_ObjectType()

vs

dotnet test -c Release
[xUnit.net 00:00:00.26] UnitTests.Issue22078Tests.SetBindingContext [FAIL] Failed UnitTests.Issue22078Tests.SetBindingContext [176 ms] Error Message: If a binding throws an exception, I kinda expect diagnostic logging :) Stack Trace: at UnitTests.Issue22078Tests.SetBindingContext()

@dotnet-policy-service dotnet-policy-service bot removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Apr 29, 2024
@kevinxufei
Copy link
Collaborator

Thanks for your explanation, executing from the command line can reproduce the issue.

@jaosnz-rep jaosnz-rep added the s/verified Verified / Reproducible Issue ready for Engineering Triage label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants