-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[xaml] fix potential NRE in {Binding}
#24756
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
will the legacy BindingExtension work ? if so, 👍 |
StephaneDelcroix
approved these changes
Sep 13, 2024
Redth
approved these changes
Sep 13, 2024
simonrozsival
approved these changes
Sep 13, 2024
/rebase |
Fixes: dotnet#24740 Using this in a project: <PackageReference Include="akgul.Maui.DataGrid" Version="4.0.4" /> Then, in a XAML file: xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid" ... <dg:DataGrid /> Would crash with: [0:] [13:46:57 FTL] Inner Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Maui.Controls.Xaml.BindingExtension.<Microsoft.Maui.Controls.Xaml.IMarkupExtension<Microsoft.Maui.Controls.BindingBase>.ProvideValue>g__CreateBinding|40_0(<>c__DisplayClass40_0& ) in /_/src/Controls/src/Xaml/MarkupExtensions/BindingExtension.cs:line 46 at Microsoft.Maui.Controls.Xaml.BindingExtension.Microsoft.Maui.Controls.Xaml.IMarkupExtension<Microsoft.Maui.Controls.BindingBase>.ProvideValue(IServiceProvider serviceProvider) in /_/src/Controls/src/Xaml/MarkupExtensions/BindingExtension.cs:line 27 at Maui.DataGrid.DataGrid.InitializeComponent() in D:\Maui.DataGrid\Maui.DataGrid\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\DataGrid.xaml.sg.cs:line 53 at Maui.DataGrid.DataGrid..ctor() in D:\Maui.DataGrid\Maui.DataGrid\DataGrid.xaml.cs:line 46 at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args) at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) Inspecting the IL, I see: BindingBase val115 = ((IMarkupExtension<BindingBase>)(object)val31).ProvideValue((IServiceProvider)null); So, it is indeed passed a `null` `IServiceProvider`. Introduce a unit test and check for `null` as a fix.
github-actions
bot
force-pushed
the
BindingExtensionNRE
branch
from
September 21, 2024 19:02
51f2d35
to
d43b55c
Compare
samhouts
added
the
fixed-in-net9.0-nightly
This may be available in a nightly release!
label
Oct 1, 2024
samhouts
added
fixed-in-9.0.0-rc.2.24503.2
and removed
fixed-in-net9.0-nightly
This may be available in a nightly release!
labels
Oct 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #24740
Context: cb0a332#diff-4f7a4722cd9e9622fcdb5c9c2a596997f8c6b7b9af8b51c5469e8ea59a3d9a48
Using this in a project:
Then, in a XAML file:
Would crash with:
Inspecting the IL, I see:
So, it is indeed passed a
null
IServiceProvider
.Introduce a unit test and check for
null
as a fix.