Reputation: 89
I'm having the weirdest issue with CustomTaskPaneFactory
in Excel-DNA 0.32
.
CustomTaskPaneFactory
throws an exception when I create a task pane with a class (MyIntCTP
) that inherits from a templated task pane (MyCTP<T>
).
Here is a example that illustrates the context:
<DnaLibrary RuntimeVersion="v4.0" Language="CS">
<Reference Path="System.Windows.Forms.dll" />
<![CDATA[
using ExcelDna.Integration;
using ExcelDna.Integration.CustomUI;
using System.Windows.Forms;
internal class ThisAddIn : IExcelAddIn
{
public void AutoOpen()
{
var p = CustomTaskPaneFactory.CreateCustomTaskPane(typeof(MyIntCTP), "o");
p.Visible = true;
}
public void AutoClose()
{ }
}
public class MyCTP<T> : UserControl
{ }
public class MyIntCTP : MyCTP<int>
{ }
]]>
</DnaLibrary>
The above code doesn't work. Excel-DNA crashes on CreateCustomTaskPane
with the following System.Runtime.InteropServices.COMException
:
Unable to create specified ActiveX control
at ExcelDna.Integration.CustomUI.ICTPFactory.CreateCTP(String CTPAxID, String CTPTitle, Object CTPParentWindow)
at ExcelDna.Integration.CustomUI.CustomTaskPaneFactory.CreateCustomTaskPane(String controlProgId, String title, Object parent)
at ExcelDna.Integration.CustomUI.CustomTaskPaneFactory.CreateCustomTaskPane(Type userControlType, String title, Object parent)
at ExcelDna.Integration.CustomUI.CustomTaskPaneFactory.CreateCustomTaskPane(Type userControlType, String title)
[...]
However it does work if the parent task pane (MyCTP
) implements an interface, as so (note that all classes are marked as public):
public interface DummyInterface
{ }
public class MyCTP<T> : UserControl, DummyInterface
{ }
I don't need the interface, but I want to keep the template. Any ideas?
Upvotes: 3
Views: 1278
Reputation: 46
I have faced the same problem.
The solution is the com visibility which will then pass the COM(Active X) object.
[ComVisible(true)]
public class MyIntCTP : MyCTP<int>
{ }
Try the following links, they will give you an overview, that will help. https://msdn.microsoft.com/en-us/library/aa942861.aspx
Have a look at the git link given below to help with project. https://github.com/KevinT/ExcelDna/blob/master/Distribution/Samples/CustomTaskPane.dna
Upvotes: 3