Cannot InitializeComponent(); WPF Docked Pane

Cannot InitializeComponent(); WPF Docked Pane

esatis
Advocate Advocate
1,092 Views
7 Replies
Message 1 of 8

Cannot InitializeComponent(); WPF Docked Pane

esatis
Advocate
Advocate

Hi, 

I have spent few days trying to figure out how to dock simple WPF pane, went through all available  tutorials yet something is not working and I cannot call InitializeComponent(); when initializing my WPF Page. 

First of all I found out that there are two ways to register dockable pane.

  1. UIControlledApplication.RegisterDockablePane
  2. UIApplication.RegisterDockablePane

Is there a difference? 

The example at UIControlledApplication.RegisterDockablePane shows this:

public Result OnStartup(UIControlledApplication application)
{
   // Create our pane provider and register it with the application
   PaneProvider prov = new PaneProvider();
   DockablePaneId id = new DockablePaneId(Guid.NewGuid());
   application.RegisterDockablePane(id, "test", prov);

   return Result.Succeeded;
}

 But if I create ViewPane (PaneProvider) like this:

public partial class ViewPane : Page, IDisposable, IDockablePaneProvider
{
	public ViewPane()
	{
		Debug.WriteLine("[ViewPane]");
		try
		{
			Debug.WriteLine("[ViewPane][InitializeComponent]");
			InitializeComponent();
		}
		catch (Exception ex)
		{
			TaskDialog.Show("[ViewPane] Error", ex.Message);
		}
	}

I get error: 
Could not load file or assembly 'AutomateWallCreation, Version=0.0.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified.

The pane is registered but black.

 

If I go the other way, with UIApplication.RegisterDockablePane:

and use ApplicationInitialized event like this:

public Result OnStartup(UIControlledApplication UIpplication)
{
	UIpplication.ControlledApplication.ApplicationInitialized += RegisterViewPane;

	return Result.Succeeded;
}
private void RegisterViewPane(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
{
	Debug.WriteLine("[RegisterViewPane]");
	var registerPaneCommand = new RegisterDockablePaneManager();
	registerPaneCommand.Execute(new UIApplication(sender as	Autodesk.Revit.ApplicationServices.Application));
}

///
///differenct class
///
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
internal class RegisterDockablePaneManager : IExternalCommand
{
	public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
	{
		return Execute(commandData.Application);
	}

	public Result Execute(UIApplication application)
	{

		Debug.WriteLine("[RegisterDockablePaneManager]");

		var data = new DockablePaneProviderData();
		var pane = new ViewPane();
		DTO.viewPane = pane;

		data.FrameworkElement = pane as FrameworkElement;

		var dpid = new DockablePaneId(DockablePaneIdentifierManager.GetViewPaneGuid());
		application.RegisterDockablePane(dpid, "ViewPane", DTO.viewPane as IDockablePaneProvider);
		return Result.Succeeded;
	}
}

I get same error: 

Could not load file or assembly 'AutomateWallCreation, Version=0.0.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified.

The pane is registered but black.

What could be the reason for failure to InitializeComponent(); at startup ? 



 

 

0 Likes
Accepted solutions (1)
1,093 Views
7 Replies
Replies (7)
Message 2 of 8

ctm_mka
Collaborator
Collaborator

This sounds like your .Addin file is not finding the compiled dll in the correct location. Check that first. The code looks fine, however can you verify that

var dpid = new DockablePaneId(DockablePaneIdentifierManager.GetViewPaneGuid());

is matching your applications GUID (the ClientID in your .Addin file)?

0 Likes
Message 3 of 8

ricaun
Advisor
Advisor

Your implementation with UIControlledApplication.RegisterDockablePane should work.

 

What do you have inside the ViewPane.xaml?

 

And where is your IDockablePaneProvider.SetupDockablePane code?

 

Should have something like this:

public void SetupDockablePane(DockablePaneProviderData data)
{
    data.FrameworkElement = this;

    data.InitialState = new DockablePaneState
    {
        DockPosition = DockPosition.Tabbed,
    };
}

 

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 4 of 8

esatis
Advocate
Advocate

Hi, the GUID is unique. The .addin is finding the .dll. The Addin Ribbon buttons and even the docked panes show up but just black.

0 Likes
Message 5 of 8

esatis
Advocate
Advocate

Hi, yes, I start to think that there is something fishing going on... Here is my code for ViewPane.xaml

 

using Autodesk.Revit.UI;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;

namespace AutomateWallCreation.Views
{
	public partial class ViewPane : Page, IDisposable, IDockablePaneProvider
	{
		public ViewPane()
		{
			Debug.WriteLine("[ViewPane]");
			try
			{
				Debug.WriteLine("[ViewPane][InitializeComponent]");
				InitializeComponent();
			}
			catch (Exception ex)
			{
				Debug.WriteLine("[ViewPane] Error: " + ex.Message);
			}
		}

		public void Initialize()
		{
			Debug.WriteLine("[ViewPane][Initialize]");
		}

		public void Dispose()
		{
			this.Dispose();
		}

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

 

 I even tried to set up it like this:

 

public void CreatePage()
{
	Debug.WriteLine("[InitializeComponent]");
	InitializeComponent();
}
/// in App.cs
public Result OnStartup(UIControlledApplication UIpplication){
UIpplication.ControlledApplication.ApplicationInitialized += RegisterViewPane;
}

private void RegisterViewPane(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
{
	Debug.WriteLine("[InitializeChatPane]");
	_viewpane.CreatePage();
}

 

Or pass it around with DTO, with no results.
InitializeComponent() just can't find dll at startup.

 

#pragma checksum "..\..\..\Views\ViewPane.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "8A1CE403566D25D902B25CDFE5EAE88481E40671"
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.Ribbon;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;


namespace AutomateWallCreation.Views {
    
    
    /// <summary>
    /// ViewPane
    /// </summary>
    public partial class ViewPane : System.Windows.Controls.Page, System.Windows.Markup.IComponentConnector {
        
        private bool _contentLoaded;
        
        /// <summary>
        /// InitializeComponent
        /// </summary>
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.12.0")]
        public void InitializeComponent() {
            if (_contentLoaded) {
                return;
            }
            _contentLoaded = true;
            System.Uri resourceLocater = new System.Uri("/AutomateWallCreation;V0.0.0;component/views/viewpane.xaml", System.UriKind.Relative);
            
            #line 1 "..\..\..\Views\ViewPane.xaml"
            System.Windows.Application.LoadComponent(this, resourceLocater);
            
            #line default
            #line hidden
        }
        
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.12.0")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
            this._contentLoaded = true;
        }
    }
}

 

 

0 Likes
Message 6 of 8

ricaun
Advisor
Advisor

The code of the ViewPane.xaml, I mean what is the content of your Page. 

 

There is a Grid with a red background or you have something more complex.

 

One easy way to test is create a new Page with a Grid and a background in red.

 

And you could add the Page in a Windows. But in your case the Initialize Component is failing, that means the problem is the ViewPane.xaml file.

 

Try to create and show a empty Windows, by the looks is not a DockablePane problem.

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 7 of 8

esatis
Advocate
Advocate
Accepted solution

 

 

<AssemblyVersion>0.0.0</AssemblyVersion>

 

 


Thank you all for suggestions, my two day struggle is over! 😤 😌
This one line in the sdk style .csproj was the fault for all the missing .dll errors. 

 

So where do I put the Assambly version information ? 

Message 8 of 8

ricaun
Advisor
Advisor

I noticed that the version was zero in the code:

/AutomateWallCreation;V0.0.0;component/views/viewpane.xaml

Didn't know that would break the wpf.

 

You could use the <Version>.

<Version>1.0.0</Version>

Now I don't know if the problem is the 0.0.0 or the AssemblyVersion, I guess is the zero version.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils