Conflict Between dSPACE and ExcelDnaUtil.Application

82 views
Skip to first unread message

Snake David

unread,
Dec 16, 2024, 10:29:44 PM12/16/24
to Excel-DNA

During recent testing of my add-in, I discovered that if I attempt to expose certain classes via COM interfaces to VBA using dSPACE.Runtime.InteropServices.BuildTasks, everything works fine as long as the add-in does not involve Excel's object model (i.e., interaction through statements like var app = (Application)ExcelDnaUtil.Application).

However, as soon as both functionalities are used together, a compilation error inevitably occurs like this(my system language isn't English) :


command“"C:\Users\ABC\.nuget\packages\dspace.runtime.interopservices.buildtasks\1.12.2\build\..\tools\x64\dscom.exe"        tlbexport "D:\Csharp\Test\bin\Debug\net6.0-windows\Test.dll" --asmpath "C:\Users\ABC\.nuget\packages\exceldna.addin\1.9.0-alpha3\build\..\tools\net462"     --out "D:\Csharp\Test\bin\Debug\net6.0-windows\\Test.tlb"”had exited, the code was 1.


Could you please advise what might be causing this issue?

Snake David

unread,
Dec 16, 2024, 10:43:21 PM12/16/24
to Excel-DNA
and here's the sample code ,basicly it's based on the sample from here: TestComServer18/MessageHandler.cs at master · govert/TestComServer18 · GitHub

using ExcelDna.Integration;
using Microsoft.Office.Interop.Excel;
using Application = Microsoft.Office.Interop.Excel.Application;
using ExcelDna.IntelliSense;
using ExcelDna.Registration;
using ExcelDna.ComInterop;
using System.Runtime.InteropServices;

namespace AComServer18
{
    [ComVisible(false)]
    public class ExcelAddin : IExcelAddIn
    {
        public void AutoOpen()
        {
            ExcelDna.ComInterop.ComServer.DllRegisterServer();
        }
        public void AutoClose()
        {
            ExcelDna.ComInterop.ComServer.DllUnregisterServer();
        }
    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface MessageEvents
    {
        void NewMessage(string s);
    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface IMessageHandler
    {
        void FireNewMessageEvent(string s);
    }

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]  // Avoid using AutoDual
    [ComSourceInterfaces(typeof(MessageEvents))]
    public class MessageHandler : IMessageHandler
    {
        public delegate void NewMessageDelegate(string s);
        public event NewMessageDelegate NewMessage;
        public MessageHandler() { }

        public void FireNewMessageEvent(string s)
        {
            //This is the code caused issue
            var app = (Application)ExcelDnaUtil.Application;
            app.ActiveCell.Value2 = 1;

            Debug.Print($"New Message {s}");
            if (NewMessage != null)
            {
                Debug.Print($"Invoke {s}");
                NewMessage.Invoke(s);
            }
        }
    }

}

and the project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
<ExcelAddInComServer>true</ExcelAddInComServer>
 <ExcelAddInTlbCreate>false</ExcelAddInTlbCreate>
    <ExcelAddInTlbExp>C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\TlbExp.exe</ExcelAddInTlbExp>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EPPlus" Version="7.4.2" />
    <PackageReference Include="ExcelDna.AddIn" Version="*-*" />
    <PackageReference Include="ExcelDna.IntelliSense" Version="1.9.0-alpha3" />
    <PackageReference Include="ExcelDna.Interop" Version="*-*" />
 <PackageReference Include="dSPACE.Runtime.InteropServices.BuildTasks" Version="*-*" />
    <PackageReference Include="ExcelDna.Registration" Version="1.9.0-alpha3" />
 <PackageReference Include="ExcelDna.Integration" Version="*-*" />
  </ItemGroup>

Govert van Drimmelen

unread,
Dec 18, 2024, 4:15:08 PM12/18/24
to Excel-DNA
I also see the problem you report.
Somehow the embedded Excel 'Application' type is not processed by dSPACE correctly.
I'll have to investigate further...

-Govert

Govert van Drimmelen

unread,
Dec 18, 2024, 4:22:58 PM12/18/24
to exce...@googlegroups.com

It looks like the problem has actually been fixed in dsCom version 1.13.0.

Duplicate ID in inheritance hierarchy. (0x800288C6 (TYPE_E_DUPLICATEID)) · Issue #317 · dspace-group/dscom

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/71ecac4a-ca41-45c3-8298-957ae5b38262n%40googlegroups.com.

Snake David

unread,
Dec 19, 2024, 2:34:42 AM12/19/24
to Excel-DNA
I've tried to upgrade dSPACE.Runtime.InteropServices.BuildTasks and it just WORKED!

I don't have to call vba macros with cumbersome and clunky reflection features any more!

thank you so much!


Reply all
Reply to author
Forward
0 new messages