Excel-DNA Add In no longer loads

458 views
Skip to first unread message

Kurt

unread,
Mar 19, 2024, 6:42:34 PM3/19/24
to Excel-DNA

 I am using Excel-DNA 1.7.0.

I have been working on this project for some weeks and everything has been running fine. I am using Visual Studio 2022 and running Office 365.   Then I started getting errors when the debugger runs the project.  It happens after the Excel splash screen shows.

I get the first error message below when running under the Visual Studio debugger and then the error message after the first one when I run from Excel (no debugger).

Two things happened just before this:  1) I tried using the Excel-DNA Intelisense.  That didn’t work on the first try to I removed that package.  2)  A few hours after this problem shows I was told that the virus scanner flagged my  .xll as potential malware.

I have read several posts on this site that might pertain to my problem but haven’t had any luck.

Oddly, when I get the Excel error (second one below) I can “Continue” and it will run the last .xll that I had before the problem surfaced just fine.  That .xll is still in place under the Excel Add In list.

I am looking for some potential paths forward.

Thanks.

*********************************************************

System.Reflection.TargetInvocationException

  HResult=0x80131604

  Message=Exception has been thrown by the target of an invocation.

  Source=System.Private.CoreLib

  StackTrace:

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in System.Reflection\RuntimeMethodInfo.cs:line 464

<snip>

  This exception was originally thrown at this call stack:

    [External Code]

 

Inner Exception 1:

MissingMethodException: Method not found: 'Void System.Windows.Forms.Control.set_Font(System.Drawing.Font)'.

****************************************************************

See the end of this message for details on invoking

just-in-time (JIT) debugging instead of this dialog box.

 

************** Exception Text **************

System.MissingMethodException: Method not found: 'Void System.Windows.Forms.Control.set_Font(System.Drawing.Font)'.

   at ExcelDna.Logging.LogDisplayForm.InitializeComponent()

   at ExcelDna.Logging.LogDisplayForm..ctor()

   at ExcelDna.Logging.LogDisplayForm.ShowForm()

*************************************************************

Kurt

unread,
Mar 20, 2024, 7:12:12 AM3/20/24
to Excel-DNA
This line in Delegate.cs

protected virtual object? DynamicInvokeImpl(object?[]? args)
{
RuntimeMethodInfo runtimeMethodInfo = (RuntimeMethodInfo)RuntimeType.GetMethodBase(methodHandle: new RuntimeMethodHandleInternal(GetInvokeMethod()), reflectedType: (RuntimeType)GetType());
return runtimeMethodInfo.Invoke(this, BindingFlags.Default, null, args, null);

Govert van Drimmelen

unread,
Mar 20, 2024, 4:25:35 PM3/20/24
to Excel-DNA
Hi Kurt,

I might be seeing an interaction between different problems.

One possible scenario:
Your add-in is failing to load, possibly because the file called ExcelDna.ManagedHost.dll that is extracted to a temp directory at runtime is blocked by your security software.
This causes Excel-DNA to try to show an error window, and when showing this window we get the set_Font error. This error relates arises from an inconsistent set of libraries between the .NET runtime and files copied from NuGet packages. I've seen this particularly when a package pulls in a newer version of SystemDrawing.Common.dll or something similar. The .NET runtime and BCL developers made some questionable choices around the 6.0.2 update of .NET, and things got fragile. (Targeting .NET Framework would avoid these dependency problems.)

You can pull these two issues apart by starting from a trivial add-in and checking that it works (this will not have the problematic dependencies, and thus might show the error form successfully). If not, you'll likely see an error form with the log entries, and not the set_Font error. This should confirm the security software block, or we can check otherwise.

Once we have figured out how to make simple a .NET 6 add-in that uses Excel-DNA 1.7.0 work again, we can go back to the dependency issue, but might need to trigger the LogDisplay explicitly to see the set_Font error again.

Any of these speculations might be wrong but could help at least eliminate possibilities. 

-Govert

Kurt

unread,
Mar 21, 2024, 10:23:11 AM3/21/24
to Excel-DNA
Thanks.

I was able to get the add in "allowed".   And I found I had a duplicate function name which I then fixed up. Everything then worked.

Thanks, again.

-Kurt

Govert van Drimmelen

unread,
Mar 21, 2024, 5:54:13 PM3/21/24
to Excel-DNA
Hi Kurt,

It would be interesting to check whether you still have the set_Font error if you now pop up the log display (I show some code below).
I suspect you would still get that error - your add-in with no error just does not automatically trigger the display.

-Govert


using ExcelDna.Integration;

namespace Test18a3
{
    public class AddIn : IExcelAddIn
    {
        public void AutoOpen()
        {
            ExcelDna.Logging.LogDisplay.Show();
        }

        public void AutoClose()
        {
        }
    }
}

Kurt

unread,
Mar 23, 2024, 6:43:57 AM3/23/24
to Excel-DNA
I added   ExcelDna.Logging.LogDisplay.Show();  to my AutoOpen.  I did not get an error but didn't get anything showing either.

-Kurt
Reply all
Reply to author
Forward
0 new messages