BuildWindowCore failed to return the hosted child window handle

BuildWindowCore failed to return the hosted child window handle

harilalmnCBXDY
Enthusiast Enthusiast
460 Views
6 Replies
Message 1 of 7

BuildWindowCore failed to return the hosted child window handle

harilalmnCBXDY
Enthusiast
Enthusiast

I have tried my best to resolve this. Any help would be greatly appreciated.

I am trying to create a plug in which should entirely run in a Dockable Pane. When I close the revit documentI get the following error message:

System.InvalidOperationException
HResult=0x80131509
Message=BuildWindowCore failed to return the hosted child window handle.
Source=PresentationFramework

The implementation is as follows;

The IExternalApplication

public class Main : IExternalApplication
{
    public Result OnShutdown(UIControlledApplication application)
    {
        return Result.Succeeded;

    }

    public Result OnStartup(UIControlledApplication application)
    {
        MyPage page1 = new MyPage();
        application.RegisterDockablePane(DockablePaneIdProvider.GetDockablePaneId(), "MyPage", (MyPage)page1);

        return Result.Succeeded;
    }
}



The IExternalCommand

public class Dockable : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        try
        {
            UIApplication uiapp = commandData.Application;
            Document document = uiapp.ActiveUIDocument.Document;

            // Show the dockable pane
            DockablePane dockablePane = uiapp.GetDockablePane(DockablePaneIdProvider.GetDockablePaneId());
            
            dockablePane.Show();

            return Result.Succeeded;
        }
        catch (Exception ex)
        {
            message = ex.Message;
            return Result.Failed;
        }
    }
}


The xaml.cs for the Page

 public partial class MyPage : Page, IDockablePaneProvider
 {
     public MyPage()
     {
         InitializeComponent();
     }

     public void SetupDockablePane(DockablePaneProviderData data)
     {
         data.FrameworkElement = this as FrameworkElement; 
         data.InitialState.DockPosition = DockPosition.Tabbed;
     }
 }


The DockablePaneIdProvider

public class DockablePaneIdProvider
{
    public static DockablePaneId GetDockablePaneId()
    {
        DockablePaneId paneId = new DockablePaneId(new Guid("3BC54A55-CB65-48F1-9520-A1B2523823A7"));
        return paneId;
    }
}



0 Likes
Accepted solutions (2)
461 Views
6 Replies
Replies (6)
Message 2 of 7

ricaun
Advisor
Advisor

Your code looks fine.

 

What do you have inside the xaml? My guess is something in there, like a webview or some unusual component.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 3 of 7

harilalmnCBXDY
Enthusiast
Enthusiast

@ricaun 
I have a TabControl in it, with 5 TabItems.

<Page
    x:Class="DocakbleUI.MyPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:DocakbleUI"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    Background="#2F2F2F"
    Foreground="#BFBFBF"
    mc:Ignorable="d">
    <Page.Resources>
        <Style TargetType="TabControl">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Margin" Value="5" />
            <Setter Property="TabStripPlacement" Value="Right" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TabControl">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <ContentPresenter
                                Grid.Column="0"
                                Content="{TemplateBinding SelectedContent}"
                                ContentStringFormat="{TemplateBinding SelectedContentStringFormat}"
                                ContentTemplate="{TemplateBinding SelectedContentTemplate}" />

                            <ScrollViewer
                                Grid.Column="1"
                                HorizontalScrollBarVisibility="Disabled"
                                VerticalScrollBarVisibility="Auto">
                                <TabPanel
                                    Background="{TemplateBinding Background}"
                                    IsItemsHost="True"
                                    KeyboardNavigation.TabIndex="1" />
                            </ScrollViewer>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>
    <Grid>
        <TabControl>
            <TabItem Name="tb_dashboard">
                <TabItem.Header>
                    <TextBlock Padding="15,0">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="270" />
                        </TextBlock.LayoutTransform>
                        Tab1
                    </TextBlock>
                </TabItem.Header>
            </TabItem>
            <TabItem Name="tb_1">
                <TabItem.Header>
                    <TextBlock Padding="15,0">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="270" />
                        </TextBlock.LayoutTransform>
                        Tab2
                    </TextBlock>
                </TabItem.Header>
            </TabItem>
            <TabItem Name="tb_2">
                <TabItem.Header>
                    <TextBlock Padding="15,0">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="270" />
                        </TextBlock.LayoutTransform>
                        Tab3
                    </TextBlock>
                </TabItem.Header>
            </TabItem>
            <TabItem Name="tb_3">
                <TabItem.Header>
                    <TextBlock Padding="15,0">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="270" />
                        </TextBlock.LayoutTransform>
                        Tagging Issues
                    </TextBlock>
                </TabItem.Header>
            </TabItem>
            <TabItem Name="tb_4">
                <TabItem.Header>
                    <TextBlock Padding="15,0">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="270" />
                        </TextBlock.LayoutTransform>
                        Tab4
                    </TextBlock>
                </TabItem.Header>
            </TabItem>
            <TabItem Name="tb_5">
                <TabItem.Header>
                    <TextBlock Padding="15,0">
                        <TextBlock.LayoutTransform>
                            <RotateTransform Angle="270" />
                        </TextBlock.LayoutTransform>
                        Tab5
                    </TextBlock>
                </TabItem.Header>
            </TabItem>
        </TabControl>
    </Grid>
</Page>

 

0 Likes
Message 4 of 7

ricaun
Advisor
Advisor

@harilalmnCBXDYare you sure the dockable is cause the BuildWindowCore issue?

 

What Revit version are you using?

 

If you create a empty Page with a simple background color the issue happens?

 

DockablePane is weird when a document is closed the dockable is unload, could be something with that.

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 5 of 7

harilalmnCBXDY
Enthusiast
Enthusiast

I am using Revit 2022 version. 
Actually my project has a MainWindow which is as WPF window, called from the command as MainWindow.Show();
That also throws the same exception and crashes.
As i have in my initial code I shared, the MainWindow of my project also has a TabControl as its content with several TabItems. The plugin runs fine. But if I close the document and try to open another document (or the same document), it crashes. That is when I tought of checking if a DocablePane would work. Tried my best in several ways like, extending the MainWindow with IDisposible, setting its owner to be Revit's window etc... nothing seemed working! Hence the post.

Attached is a video of the DockablePane crashing Revit.

0 Likes
Message 6 of 7

ricaun
Advisor
Advisor
Accepted solution

Hmmm, is kinda hard to know what is creating the issue is you are running more code at the same time.

 

If MainWindow was already breaking the problem could be in there. I don't know what you are doing to binding stuff in the xaml.

 

The code you show to register a Dockable Pane should work, so I suggest you to comment all the code that is not related to register a Dockable Pane with a color to check if works. You could create a new project as well.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 7 of 7

harilalmnCBXDY
Enthusiast
Enthusiast
Accepted solution

I had removed everything I had from the Addins folder except for PyRevit, AddinManager and RevitLookup. Rebuilt everything and this time it worked...!

 

But I don't know how to recreate the bug,  hence the problem, though it is temporarily somehow resolved, the possibility of it getting back anytime, is a concern. Ah.. will see that then.

 

@ricaun Thanks for your responses...