Excel-DNA / Excel-DNA/Excel-DNA.github.io

Docs: Custom Task Panes section omits the .NET 6+ COM default-interface requirement

Abierto Apto para principiantes
#17 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
0
Forks
4
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Summary

`src/pages/reference-various.md` → **Custom Task Panes** documents the CTP API but not the COM attribution a `UserControl` needs on .NET 6+. Without it, `CustomTaskPaneFactory.CreateCustomTaskPane` fails with a bare `E_FAIL` (`0x80004005`) and no diagnostic text.

This is already known — you answered it in [issue #558](https://github.com/Excel-DNA/ExcelDna/issues/558) and in the group thread [*CustomTaskPaneFactory.CreateCustomTaskPane throws 'Unable to create specified ActiveX control'*](https://groups.google.com/g/exceldna/c/onRDZLJwoBY):

> You now need an explicit 'default interface' for your type - this will cause the class to implement IDispatch (if it is ComVisible).

The reference page doesn't carry that, so it's still reachable by reading the docs alone.

### What I measured

Standalone add-in, no other dependency, `ExcelDna.AddIn` 1.9.0, SDK 10.0.400, Excel 16.0.20326.20112 x64 Click-to-Run Current Channel, Windows 11 25H2 26200.9168, not elevated, Defender only, Trust Center at defaults.

Control under test:

```csharp
[ComVisible(true)]
public sealed class FixedLabelControl : UserControl
{
public FixedLabelControl() => Controls.Add(new Label { Text = "Repro Pane", AutoSize = true });
}
```

| Target | Runtime | Result |
|---|---|---|
| `net10.0-windows` | 10.0.11 | `COMException`, HRESULT `-2147467259` (`0x80004005`) |
| `net7.0-windows` | 7.0.7 | `COMException`, HRESULT `-2147467259` (`0x80004005`) |

Byte-identical source both times; only the TFM differed. Adding the documented attribution and changing nothing else:

```csharp
[ComVisible(true)]
[Guid("...")]
public interface IFixedLabelControl { }

[ComVisible(true)]
[Guid("...")]
[ComDefaultInterface(typeof(IFixedLabelControl))]
public sealed class FixedLabelControl : UserControl, IFixedLabelControl { ... }
```

`net10.0-windows` then completed the full lifecycle — create, show, hide, delete, dispose — with no HRESULT.

Because the requirement splits .NET Framework from .NET Core rather than one .NET version from another, a net7-vs-net10 comparison can't discriminate it: both fail identically. That cost me a fair amount of bisecting before I found #558, which is really the motivation for this request.

### Suggested addition

After the `CreateCustomTaskPane` example in the **Custom Task Panes** section:

> **.NET 6 and later:** the control needs an explicit COM default interface. .NET Framework generated a class interface automatically, so a `[ComVisible(true)] UserControl` had a usable `IDispatch`; .NET Core and later do not, and `CreateCustomTaskPane` then fails with `E_FAIL` / "Unable to create specified ActiveX control".
>
> ```csharp
> public interface IMyUserControl { }
>
> [ComVisible(true)]
> [Guid("....")]
> [ComDefaultInterface(typeof(IMyUserControl))]
> public class MyUserControl : UserControl, IMyUserControl { }
> ```

Happy to open a PR against `src/pages/reference-various.md` if that's easier.

### Separately, if it's ever cheap to do

`ExcelCustomTaskPane.CreateCustomTaskPane` already logs a helpful message for the `UnauthorizedAccessException` registry case. A comparable hint when `ICTPFactory.CreateCTP` throws `E_FAIL` — pointing at the default-interface requirement — would make this self-diagnosing. Entirely optional; the docs change is the ask.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Abre src/pages/reference-various.md y lee la sección Custom Task Panes, especialmente el ejemplo CreateCustomTaskPane; compáralo con las indicaciones de issue #558. Añade después de esa sección el requisito explícito de la interfaz predeterminada de COM para .NET 6+ y un ejemplo, manteniendo separada la modificación de diagnóstico opcional. Se considerará terminado cuando la página de referencia explique la causa de E_FAIL y muestre claramente la atribución requerida.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp
Área
documentation
Tipo de issue
Documentación
Dificultad
1/5
Tiempo estimado
1-3 horas
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
88/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.