CustomTaskPaneFactory.CreateCustomTaskPane throws 'Unable to create specified ActiveX control'

391 views
Skip to first unread message

Kenneth Gabriel Birkedahl Fabricius

unread,
Jun 21, 2022, 5:15:42 AM6/21/22
to Excel-DNA
Hi Govert

Thank you for a very nice and easy-to-use library.

I am in the process of convert my existing add-in to .Net 6 by basing it on v. 1.6.0-preview3. In the add-in, I have a couple of CustomTaskPanes, which are created using your CustomTaskPaneFactory.CreateCustomTaskPane(...)-method.

This has worked like a charm up until now, when compiling against .Net 4.7.2, both when basing it on v. 1.5.1 and on v. 1.6.0-preview3 of Excel-DNA, however, if I change the TargetFrameWork to net6.0-windows instead of net472, I run into trouble.

In that case, I get an error whenever I try to create the CustomTaskPane: "Unable to create specified ActiveX Control"

It only happens, after I change TargetFramework.

I have attached a minimal working example to reproduce to issue. It is an add-in with a Ribbon-tab containing a single button for showing the task pane.
It compiles against both net472 and net6.0-windows.

Please let me know, if you need anything else.

Best,
Kenneth
CustomPaneAddIn.zip
StackTrace.png

Govert van Drimmelen

unread,
Jun 21, 2022, 7:13:28 AM6/21/22
to Excel-DNA
Hi Kenneth,

I checked your project and see the same error.
I somehow recall checking CTP panes with .NET 6.0, but I can't see that sample now.
There was also an issue where the default COM interfaces that a class implements changes when going to .NET 6, requiring an extra attribute annotation.
But I don't find the reference now, and will need to dig a bit.

-Govert

Govert van Drimmelen

unread,
Jun 24, 2022, 3:49:42 PM6/24/22
to Excel-DNA
Hi Kenneth,

I finally found the place where I figured out the CTP story with .NET 6!
It was in February, but I had completely forgotten about it.

The sample was part of the first project in the sponsors-only repository on GitHub.
You can encourage support and further development of Excel-DNA by signing up as a sponsor - see Sponsor @Excel-DNA on GitHub Sponsors
The low tier is at $14 per month, and you can cancel at any time.
Maybe you'd like to consider that :-)

Anyway, the main discovery I made in February that is relevant to your question relates to how COM interfaces are exposed with .NET 6.
You now need an explicit 'default interface' for your type - this will cause the class to implement IDispatch (if it is ComVisible).
So you can change your code with an empty interface like this:

    public interface IMyUserControl { }

    [ComVisible(true)]
    [Guid("E2197CEB-6ADC-4EAB-80FD-0A9EE161BA14")]
    [ComDefaultInterface(typeof(IMyUserControl))]
    public class MyUserControl : UserControl, IMyUserControl { }


Then the control should appear correctly.
Information regarding this issue and where I found the fix is here: https://github.com/dotnet/winforms/issues/4370#issuecomment-798828348
I don't understand why marking the class with [ClassInterface(ClassInterfaceType.AutoDispatch)] does not work for creating an IDispatch interface in this scenario.

-Govert

Kenneth Gabriel Birkedahl Fabricius

unread,
Jun 27, 2022, 3:33:02 AM6/27/22
to Excel-DNA
Hi Govert

Thank you very much for you quick reply. It was exactly what I was looking for. Adding the ComDefaultInterface attribute did the trick!

As mentioned, I am in the process of converting our existing Add-In to the .Net 6 equivalent using your library. If everything goes well (which I expect) we are surely considering signing up for a sponsorship.

Best,
Kenneth
Reply all
Reply to author
Forward
0 new messages