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

Border: PlatformView cannot be null here | Happens randomly in release builds. #27194

Open
bhavanesh2001 opened this issue Jan 17, 2025 · 2 comments
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Milestone

Comments

@bhavanesh2001
Copy link

bhavanesh2001 commented Jan 17, 2025

Description

We are encountering a random issue in our .NET MAUI [.NET 8] application(only targets android) in release builds where an System.InvalidOperationException is being thrown.

Although the exception occurs randomly in different parts of the app, the stack trace in Sentry consistently points to the Stroke Shape mapper method in the MAUI source code. This may be due to the way we defined our Border Styles.

This leads us to believe the issue might originate from the MAUI framework itself.

Here's are couple of stack trace's i get from sentry

Stack Trace 1

System.InvalidOperationException: PlatformView cannot be null here
  ?, in ContentViewGroup ViewHandler<IBorderView, ContentViewGroup>.get_PlatformView()
  ?, in ContentViewGroup BorderHandler.Microsoft.Maui.Handlers.IBorderHandler.get_PlatformView()
  ?, in void BorderHandler.MapStrokeShape(IBorderHandler handler, IBorderView border)
  ?, in void PropertyMapper<TVirtualView, TViewHandler>.Add(string key, Action<TViewHandler, TVirtualView> action)+(IElementHandler h, IElement v) => { }
  ?, in void PropertyMapper.UpdatePropertyCore(string key, IElementHandler viewHandler, IElement virtualView)
  ?, in void PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, string property)
  ?, in void ElementHandler.UpdateValue(string property)
  ?, in void Border.OnPropertyChanged(string propertyName)
  ?, in void Border.NotifyStrokeShapeChanges()+(object sender, PropertyChangedEventArgs e) => { }
  ?, in void WeakNotifyPropertyChangedProxy.OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  ?, in void BindableObject.OnPropertyChanged(string propertyName)
  ?, in void Element.OnPropertyChanged(string propertyName)
  ?, in void RoundRectangle.OnPropertyChanged(string propertyName)
  ?, in void Element.SetParent(Element value)
  ?, in void Element.OnChildAdded(Element child)
  ?, in void VisualElement.OnChildAdded(Element child)
  ?, in void Element.AddLogicalChild(Element element)
  ?, in void Border.NotifyStrokeShapeChanges()
  ?, in static Border()+(BindableObject bindable, object oldvalue, object newvalue) => { } [0]
  ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent)
  ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
  ?, in void BindableObject.SetValue(BindableProperty property, object value, SetterSpecificity specificity)
  ?, in void Setter.Apply(BindableObject target, SetterSpecificity specificity)
  ?, in void Style.ApplyCore(BindableObject bindable, Style basedOn, SetterSpecificity specificity)
  ?, in void Style.Microsoft.Maui.Controls.IStyle.Apply(BindableObject bindable, SetterSpecificity specificity)
  ?, in void MergedStyle.SetStyle(IStyle implicitStyle, IList<Style> classStyles, IStyle style)
  ?, in void MergedStyle.set_Style(IStyle value)
  ?, in static NavigableElement()+(BindableObject bindable, object oldvalue, object newvalue) => { }
  ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent)
  ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
  ?, in void BindableObject.SetValue(BindableProperty property, object value)
  ?, in void NavigableElement.set_Style(Style value)
  ?, in void EditedPage.InitializeComponent()
...

Stack Trace 2

System.InvalidOperationException: PlatformView cannot be null here
  ?, in ContentViewGroup ViewHandler<IBorderView, ContentViewGroup>.get_PlatformView()
  ?, in ContentViewGroup BorderHandler.Microsoft.Maui.Handlers.IBorderHandler.get_PlatformView()
  ?, in void BorderHandler.MapStrokeShape(IBorderHandler handler, IBorderView border)
  ?, in void PropertyMapper<TVirtualView, TViewHandler>.Add(string key, Action<TViewHandler, TVirtualView> action)+(IElementHandler h, IElement v) => { }
  ?, in void PropertyMapper.UpdatePropertyCore(string key, IElementHandler viewHandler, IElement virtualView)
  ?, in void PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, string property)
  ?, in void ElementHandler.UpdateValue(string property)
  ?, in void Border.OnPropertyChanged(string propertyName)
  ?, in void Border.NotifyStrokeShapeChanges()+(object sender, PropertyChangedEventArgs e) => { }
  ?, in void WeakNotifyPropertyChangedProxy.OnPropertyChanged(object sender, PropertyChangedEventArgs e)
  ?, in void BindableObject.OnPropertyChanged(string propertyName)
  ?, in void Element.OnPropertyChanged(string propertyName)
  ?, in void RoundRectangle.OnPropertyChanged(string propertyName)
  ?, in void Element.SetParent(Element value)
  ?, in void Element.OnChildAdded(Element child)
  ?, in void VisualElement.OnChildAdded(Element child)
  ?, in void Element.AddLogicalChild(Element element)
  ?, in void Border.NotifyStrokeShapeChanges()
  ?, in static Border()+(BindableObject bindable, object oldvalue, object newvalue) => { } [0]
  ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent)
  ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
  ?, in void BindableObject.SetValue(BindableProperty property, object value, SetterSpecificity specificity)
  ?, in void Setter.Apply(BindableObject target, SetterSpecificity specificity)
  ?, in void Style.ApplyCore(BindableObject bindable, Style basedOn, SetterSpecificity specificity)
  ?, in void Style.Microsoft.Maui.Controls.IStyle.Apply(BindableObject bindable, SetterSpecificity specificity)
  ?, in void MergedStyle.SetStyle(IStyle implicitStyle, IList<Style> classStyles, IStyle style)
  ?, in void MergedStyle.set_Style(IStyle value)
  ?, in static NavigableElement()+(BindableObject bindable, object oldvalue, object newvalue) => { }
  ?, in void BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, bool silent)
  ?, in void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
  ?, in void Element.OnResourceChanged(BindableProperty property, object value, SetterSpecificity specificity)
  ?, in void Element.OnSetDynamicResource(BindableProperty property, string key, SetterSpecificity specificity)
  ?, in void BindableObject.SetDynamicResource(BindableProperty property, string key, SetterSpecificity specificity)
  ?, in void BindableObject.Microsoft.Maui.Controls.Internals.IDynamicResourceHandler.SetDynamicResource(BindableProperty property, string key)
  ?, in void EditedPage.InitializeComponent()
...

The exception is always thrown during page initialization, specifically from InitializeComponent(). as indicated in the stack traces.

We have style's defined for Border in App.xaml, something like below

  <Style x:Key="BorderStyle" TargetType="Border">
      <Setter Property="StrokeShape">
          <Setter.Value>
              <RoundRectangle CornerRadius="8"/>
          </Setter.Value>
      </Setter>
      <Setter Property="StrokeThickness" Value="1" />
      <Setter Property="HorizontalOptions" Value="FillAndExpand" />
      <Setter Property="BackgroundColor" Value="#FFFFFF" />
  </Style>

We are applying these style's either as Style={StaticResource BorderStyle} or Style = {DynamicReosource BorderStyle}

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.93 SR9.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

No response

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

@bhavanesh2001 bhavanesh2001 added the t/bug Something isn't working label Jan 17, 2025
@samhouts samhouts added platform/android 🤖 area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing labels Jan 17, 2025
@PureWeen PureWeen added the s/needs-repro Attach a solution or code which reproduces the issue label Jan 17, 2025
@PureWeen PureWeen added this to the .NET 9 SR5 milestone Jan 17, 2025
Copy link
Contributor

Hi @bhavanesh2001. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@PureWeen
Copy link
Member

@jsuarezruiz @StephaneDelcroix

I'm curious about the implementation of StrokeShape on Border

I feel like we've talked about this a little bit at some point. The code here is using StrokeShape in a staticresource which seems fine?

But in border we're adding the stroke shape as a logical child

void NotifyStrokeShapeChanges()
{
var strokeShape = StrokeShape;
if (strokeShape is VisualElement visualElement)
{
AddLogicalChild(visualElement);
_strokeShapeChanged ??= (sender, e) =>
{
if (e.PropertyName != nameof(Window) &&
e.PropertyName != nameof(Parent))
{
OnPropertyChanged(nameof(StrokeShape));
}
};
_strokeShapeProxy ??= new();
_strokeShapeProxy.Subscribe(visualElement, _strokeShapeChanged);
}
}

This is something that we "fixed" at one point but had to revert wasn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants