question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a TabViewItem derived class to TabView crashes the application

See original GitHub issue

Describe the bug

If I add a class derived from TabViewItem to TabView, it crashed the application with

ComCallHelpers.Call (__ComObject, RuntimeTypeHandle, Int32)
System.Exception: No installed components were detected. ListViewItemPresenter can only be used as the first child in the template for a ListViewItem.

StackTrace from AppCenter

System.Runtime.InteropServices
McgMarshal.ThrowOnExternalCallFailed (Int32 hr, RuntimeTypeHandle typeHnd) f:\dd\ndp\fxcore\CoreRT\src\System.Private.Interop\src\Shared\McgMarshal.cs at 1189:13
__Interop
ComCallHelpers.Call (__ComObject, RuntimeTypeHandle, Int32)
__Interop
ForwardComStubs.Stub_12[TThis] (__ComObject, Int32)
Microsoft.AppCenter.Utils
ApplicationLifecycleHelper.<ctor>b__17_1 (Object, UnhandledErrorDetectedEventArgs)

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Use following code to add
public class TabularItem : TabViewItem
{
        public TabularItem()
        {
        }
 }
private void AddTabItem(TabView tabView) 
{
    var newTab = new TabularItem();
 
    // The Content of a TabViewItem is often a frame which hosts a page.
    var frame = new Frame();
    newTab.Content = frame;
    frame.Navigate(typeof(OptionPage));
    tabView.TabItems.Add(newTab);
}

Expected behavior

Screenshots

Version Info

NuGet package version:

Microsoft.UI.Xaml 2.4.0

Windows 10 version Saw the problem?
Insider Build (xxxxx)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134) Yes
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
harvinderscommented, Jun 24, 2020

@ranjeshj I just tested it, the fix works.

0reactions
ranjeshjcommented, Jun 24, 2020

Try adding the Bindable attribute on the custom type. In debug builds the metadata is obtained through reflection but in release builds it is code gen which causes issues like this one. This issue documents a couple of differences between debug and release builds.

 [Bindable]
    public class MyTabViewItem: TabViewItem
    {
        public MyTabViewItem()
        {
            Content = "new";
        }
    }
```
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid app crash with TabView inside ...
I'm using a TabView inside NavigationView but my app crashes when I try to navigate backwards, it shows this error message "Thread 1: ......
Read more >
iOS 15 More Tab Crash | Apple Developer Forums
The app I'm working on crashes by trying to reference a deallocated object. The object is a subclass of UITabBarController, and this crash...
Read more >
Android, crashes when nested inside a tabview
Hi John, This error isn't specifically related to UI for Xamarin, but rather because you're attempting to add an element that already exists....
Read more >
Xamarin forms templatedview. I'm trying to do a content button ...
Xamarin forms templatedview. I'm trying to do a content button with only shared code (no native project code, so no renderer and no...
Read more >
Windows Community Toolkit | XAML Brewer, by Diederik Krols
Here's how our sample app looks like: It covers: programmatical TabViewItem creation,; creating a reusable 'TabsWindow' control,; drag-and-drop ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found