Could not load ExcelDna.Integration

226 views
Skip to first unread message

Michele

unread,
Jan 7, 2022, 5:49:13 PM1/7/22
to Excel-DNA
Hi,
I had 2 projects in my solution, both of which produced Excel Addin XLL files and both of which wrote to the same output folder. The first project referenced ExcelDna.Integration version 1.1.0 only (no reference to ExcelDna.AddIn) and the second project referenced ExcelDna.Integration 1.1.0 and ExcelDna.AddIn 1.1.1. 

The first project was unused so I removed it from the solution. After I did that, I started getting an exception saying "Could not load file or asesmbly 'ExcelDna.Integration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe' or one of its dependencies"' when I ran the excel addin produced by the second project.

I noticed that ExcelDna.Integration.dll does appear in the output folder when the first project is present in the solution, and it disappears when I remove the first project from the solution.

My first idea for a fix was to somehow get the ExcelDna.Integration.dll back into the output folder, but I've been reading about it and it seems like it isn't required there. But then why am I getting that exception?

Thanks,
Michele

Govert van Drimmelen

unread,
Jan 8, 2022, 1:15:02 AM1/8/22
to exce...@googlegroups.com

Hi Michele,

 

You’re right that the file ExcelDna.Integration.dll does not have to be in the output directory.

A version of this is already packed inside the .xll file.

 

I suggest you uninstall any ExcelDna packages from your project, make sure there are no ExcelDna.* files left under the project folder or its packages folder.

Also check that you then have no reference in your project to some ExcelDna.Integration assembly somewhere else.

Then reinstall the ExcelDna.AddIn package, and everything should be set up correctly.

 

If that doesn’t work, write back and I can try to think of some more steps to debug the situation.

 

-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 on the web visit https://groups.google.com/d/msgid/exceldna/0d97fcf4-c4e8-473c-8baa-bf8b32ee38e0n%40googlegroups.com.

Michele Olsen

unread,
Feb 2, 2022, 4:21:58 PM2/2/22
to exce...@googlegroups.com
Thank you for your response Govert. I tried what you suggested and I noticed that when I run my XLL via excel it works fine. The error only comes when I am running Program.cs as a stand-alone application. So I’m thinking that in that case, it does need the ExcelDna.Integration in the output directory. I have tried to get it there by setting copyLocal=true but that doesn’t work, I’m guessing because of the code I see in the targets file that explicitly removes that DLL. Is there any way for me to get ExcelDna.Integration into the output directory?

On Jan 8, 2022, at 1:15 AM, Govert van Drimmelen <govert.va...@gmail.com> wrote:


You received this message because you are subscribed to a topic in the Google Groups "Excel-DNA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/exceldna/ZNAZrSPJru0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/023701d80457%240f065a10%242d130e30%24%40gmail.com.

Pa...@MargusConsulting.com

unread,
Jun 26, 2022, 3:35:41 PM6/26/22
to Excel-DNA
Hello --

I am having similar problems whenever I execute the following code:

        gxlApplication = ExcelDnaUtil.Application

I get exactly the same message as Michele: "Could not load file or assembly 'ExcelDna.Integration, Version=1.1.0.0"  (Regardless of the versions actually installed, the message ALWAYS says "Version=1.1.0.0".)

And in the absence of the above "ExcelDnaUtil" invocation, I NEVER get the error message.

I am using the following:
  • Visual Basic
  • Excel VSTO Add-In
  • .NET Framework   4.8    ("Excel VSTO Add-In" doesn't permit a later version.)
  • Ribbon (XML)
  • ExcelDna.AddIn    1.5.1
  • ExcelDna.Integration    1.5.1
  • ExcelDna.Interop    14.0.1
  • Excel Ona.Registration    1.5.1
  • ExcelDna.Registration.VisualBasic    1.5.1
P.S.:  My ultimate motivation is to get the following objects:
  • gxlApplication.ActiveWorkbook
  • gxlApplication.Selection
  • gxlApplication.ThisWorkbook
  • gxlApplication.WorksheetFunction (for example, "WorksheetFunction.Days360").
Therefore, if we can't directly solve the problem, I'll be delighted with any workaround that gets the above 4 objects.

Thanks in advance.

Govert van Drimmelen

unread,
Jun 27, 2022, 6:01:13 AM6/27/22
to Excel-DNA
Hi Paul,

Are you also like Michele trying to use Excel-DNA from outside Excel, not in an Excel add-in setting?

If so, this will not work - Excel-DNA can only be used inside the Excel process in an add-in.
You can automate Excel from outside, and get to the Excel Application object in other ways.
But then Excel-DNA won't be involved.

If you are seeing this inside an Excel add-in, it is unusual to get an error here.
What is the context where you are making the ExcelDnaUtil.Application call - a Ribbon callback, a UDF call etc. ?

-Govert

Pa...@MargusConsulting.com

unread,
Jun 27, 2022, 5:43:33 PM6/27/22
to Excel-DNA

Hi Govert –

 Thanks for your amazingly quick reply.

In answer to your first question, I am working solely within an "Excel VSTO add-in" setting.  I created an "Excel VSTO solution" and used the “NuGet Package Manager” to install the following:

    • ExcelDna.AddIn    1.5.1
    • ExcelDna.Integration    1.5.1
    • ExcelDna.Interop    14.0.1
    • ExcelDna.Registration    1.5.1
    • ExcelDna.Registration.VisualBasic    1.5.1

    In answer to your second question, following is my “ThisAddIn” coding.  When gxlApplication = ExcelDnaUtil.Application” executes, I get the “Could not load file or assembly ExcelDna.Integration” error, and the ribbon tab isn’t created.

     Imports ExcelDna.Integration

     Public Class ThisAddIn

         Public Shared gxlApplication As Excel.Application

         Private Sub ThisAddIn_Startup() Handles Me.Startup

              ' ========= The following statement generates the error. =========

            gxlApplication = ExcelDnaUtil.Application

             MsgBox(Prompt:="gxlApplication.Application.Name=" & gxlApplication.Application.Name, Title:="ThisAddIn_Startup")

         End Sub

         Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

             MsgBox(Prompt:="gxlApplication.Application.Name=" & gxlApplication.Application.Name, Title:="ThisAddIn_Shutdown")

         End Sub

         Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility

             Return New RibbonKalends()

         End Function

     End Class

     I have explored an alternative:

            gxlApplication = Globals.ThisAddIn.Application

            ' see      https://stackoverflow.com/questions/10347495/excel-program-using-c-sharp-vsto#answer-10361091

     The  alternative appears to execute properly, up to a point:

    • Both MsgBox statements work as expected.
    • The gxlApplication object is also accessible within RibbonKalends.vb.
    • HOWEVER, it has a Nothing value within all other Modules and Classes.  In particular, it's Nothing within my user-defined spreadsheet functions. Therefore I get errors in gxlApplication.Selection, gxlApplication.WorksheetFunction, etc.

    Thus, the gxlApplication object works fine on Startup and Shutdown, but is Nothing at chronologically intermediate locations.  Very strange.

    Thanks for taking the time to look at this.

     -- Paul

    Govert van Drimmelen

    unread,
    Jun 27, 2022, 6:02:39 PM6/27/22
    to exce...@googlegroups.com

    Hi Paul,

     

    Excel-DNA is not designed to work as part of a VSTO add-in, though I don’t really know what the implications or blocks would be in this setting. Where possible, Excel-DNA attempts to be an alternative to VSTO (for Excel)

     

    The context where VSTO loads the add-in for the first time, and runs the Startup routine might be one where Excel-DNA cannot find the COM Application object. For VSTO I think there is a an “Application” object available everywhere (I guess that’s the ThisAddIn.Application), so I’m not sure why you need to get it through the Excel-DNA mechanism. But you report having a problem with this approach too – I’m not sure why.

     

    What I would suggest is to not make the add-in a VSTO add-in. So you just make a “Library (.NET Framework)” project and install the Excel-DNA packages.

    Then you handle the startup like this:

     

    Imports ExcelDna.Integration

     

    Public Class MyAddIn

        Implements IExcelAddIn

     

        Public Sub AutoOpen() Implements IExcelAddIn.AutoOpen

            MsgBox("Add-In Loaded")

     

        End Sub

     

        Public Sub AutoClose() Implements IExcelAddIn.AutoClose

        End Sub

    End Class

     

    There are some aspects you lose when taking out the VSTO part:

    • VSTO has some high-level ribbon wrappers, which Excel-DNA does not have. So you have to code against the (somewhat awkward) raw ribbon interface and callbacks. The capabilities are the same, but you might need a bit more code.
    • VSTO allows you to extend Workbooks and Worksheets with some high-level wrappers, in particular I remember some ‘List’ objects for tables that handle events and data binding. Again this is a wrapper over the basic Excel object model, so with some extra code you can do the same.
    • VSTO lets you bind a project to a workbook in some way – so your add-in is not a general one available to all workbooks, but somehow tied to a particular one. I don’t know much about this, but Excel-DNA does not have access to the Excel hooks that make this possible.

     

    If you really need these VSTO abilities, you might need to make two add-ins, one as a normal VSTO add-in that does not reference Excel-DNA at all, and the other an Excel-DNA add-in that does not reference VSTO at all, and exposes the worksheet UDFs that VSTO can’t provide. The Excel-DNA add-in would be completely separate, though it can be loaded automatically by the VSTO add-in using a call to Application.RgisterXLL(…).

     

    Over the long term, I think you’re better off without VSTO if possible and a simpler add-in using just Excel-DNA.

    Reply all
    Reply to author
    Forward
    0 new messages