maui
maui copied to clipboard
Unable to convert Microsoft.Maui.Handlers.LayoutHandler to UIKit.UIView
Description
In my application, I have a control that basically consists of several Grid components inside a FlexLayout. When one of the grids is clicked, it should change its opacity via FadeTo. However, as soon as I click, I receive this error message:
As it's corporate code, I cannot share any of it, and I was not able to reproduce it in a simple project (I tried to rebuild the control without the business logic, but there it worked perfectly fine. However, the logic does not do that much). Does anyone maybe have a clue what could be the cause?
StackTrace:
Unable to convert Microsoft.Maui.Handlers.LayoutHandler to UIKit.UIView
at Microsoft.Maui.ElementHandlerExtensions.ToPlatform(IElementHandler elementHandler)
at Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler(IViewHandler viewHandler, Rect rect)
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].PlatformArrange(Rect rect)
at Microsoft.Maui.Controls.Compatibility.Platform.iOS.HandlerToRendererShim.OnBatchCommitted(Object sender, EventArg`1 e)
at Microsoft.Maui.Controls.VisualElement.BatchCommit()
at Microsoft.Maui.Controls.AnimationExtensions.HandleTweenerUpdated(Object o, EventArgs args)
at Microsoft.Maui.Controls.Tweener.<Start>b__28_0(Int64 step)
at Microsoft.Maui.Controls.TweenerAnimation.OnTick(Double millisecondsSinceLastUpdate)
at Microsoft.Maui.Animations.Animation.Tick(Double milliseconds)
at Microsoft.Maui.Animations.AnimationManager.<>c__DisplayClass20_0.<OnFire>g__OnAnimationTick|0(Animation animation)
at System.Collections.Generic.List`1[[Microsoft.Maui.Animations.Animation, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ForEach(Action`1 action)
at Microsoft.Maui.Animations.AnimationManager.OnFire()
at Microsoft.Maui.Animations.PlatformTicker.<Start>b__3_0()
at Foundation.NSActionDispatcher.Apply()
From what I gathered, the ToPlatform() implementation returns something that is not a UIKit.UIView, but how can this happen?
Steps to Reproduce
None found
Link to public reproduction project repository
""
Version with bug
Unknown/Other (please specify)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 16
Did you find any workaround?
No response
Relevant log output
No response
Maybe you can share the project or a smaller sample via email?. Let me know and we can share emails or whatever you need. Can share a piece of XAML?, are you using the compatibility layer for Layouts?
Hi @owl-guy. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.
@jsuarezruiz Thanks, I will discuss this proposal with my colleagues. What I can say is that I use a FlexLayout. I tried both the compat and the normal version, happens in both of them.
@owl-guy are you registering any compatibility renderers? or using compatibility Community Toolkit?
Hi @owl-guy. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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 In fact I do use a compatibilty renderer. It's a CustomRenderer that was used in Xamarin.Forms to customize the appearance of a ContentPage. After omitting it, the problem did not occur again. What can be the reason for that?
@owl-guy Are you using the old Compatibility Grid or the new version of Grid?
Hi @owl-guy. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
@rachelkang Our control looks something like this:
<ContentView>
<Grid>
<ContentView />
<compat: FlexLayout>
<BindableLayout.ItemTemplate>
<Grid>
<Label />
<Image />
</Grid>
</BindableLayout.ItemTemplate>
</compat: FlexLayout>
<ContentView />
</Grid>
</ContentView>
FlexLayout is taken from the Compatibility namespace.
Our CustomRenderer uses the ExportRenderer attribute from the Microsoft.Maui.Controls.Compatibility namespace and derives from PageRenderer in using Microsoft.Maui.Controls.Compatibility.Platform.iOS. We plan on replacing our old renderers with new handlers anyway, but sure would be interesting to know what is causing this error.
@owl-guy if you change that code to not use the compat:FlexLayout
you get the same crash?
@PureWeen yes, I get the same crash. Interesting enough, I do not get this crash when I copy the xaml and implement a simplified version of the business logic. Furthermore, I refactored the code a bit, removed unnecessary calls etc., and now it works.
To summarize, you say it now works, is there still something actionable that we can do here? Thanks!
Hi @owl-guy. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.
@jfversluis I do not think there is anything you can do there. As it cannot be reproduced in a blank project and seems to concern a compatibility renderer we will replace anyways, let us leave it at that. I will open a new issue if that problem happens again. Thank you all so much for your help.