Unable to launch Excel addin on Windows 11 PC

425 views
Skip to first unread message

Gargi Biswas

unread,
Apr 16, 2024, 11:08:04 AM4/16/24
to Excel-DNA

Hello,

 

I am trying to run an Excel addin (implemented in C# using ExcelDna library) which is working fine with MS-Excel on Windows 10(my work pc).
I am trying to the test the addin on a test Windows11 pc but I see that it throws a TargetInvocationException ERROR whenever I launch it in Excel.

 

I have tried repairing the MS-Office Suite as I found what others did on the web but in vain.

I have also tried putting try…catch in my addin::AutoOpen() override to catch the Exception occurring and display it in an error box/file.

 

The exception is occurring during Auto-open because when I try to print it in an ErrorBox I do see my screen blurring into something green but not able to print a box.

But, I don’t get any file output at all when I try to log it in file.

 

Can you please help me on how I can get the addin working on Windows11 or any changes needed to make it working?


Thanks and Regards
Gargi Biswas

Kedar Kulkarni

unread,
Apr 16, 2024, 11:17:15 AM4/16/24
to Excel-DNA
unfortunately, that image is not visible..  are you able to log the error message / attach the debugger at startup by adding a messagebox statement at auto_open start and reproducing the error? Make sure that you have selected all checkboxes from the Debug => Exception Settings.

Govert van Drimmelen

unread,
Apr 16, 2024, 5:06:53 PM4/16/24
to Excel-DNA
Hi Gargi,

There's nothing special about Windows 11 for Excel-DNA add-ins.
I know of at least some cases that work fine and have had no other Windows 11 specific reports.

Can you give some more details about the problem add-in?
* What is the exact Excel-DNA version you are using?
* What is the .NET version you are targeting?
* What interesting code do you run in the AutoOpen?

You might try a very basic add-in, targeting .NET Framework 4.8, as a first test.

You should also look out for anti-virus or other security software that might be blocking Excel-DNA.
It you are targeting .NET 6+, you might look out for other security settings that might be blocking the add-in from working - for example see this discussion: Attack surface reduction (google.com)

Please write back with anything you find.

-Govert

Gargi Biswas

unread,
Apr 17, 2024, 3:35:32 AM4/17/24
to Excel-DNA
Hi Govert,
This is the error message that is cropping up. I checked the details that you mentioned as well. 
image005.jpg

* What is the exact Excel-DNA version you are using? 30.22.1
* What is the .NET version you are targeting? 4.8.1
* What interesting code do you run in the AutoOpen? It tries to do Path.DirectoryName(ExcelDnaUtil.XllPath)
and then opens the config file present in that folder. But it doesnt get to this point at all, because locally I ran it on windows 10 to show an errorbox alert when these are executed, but the box doesn't pop up on win11.

I also added the Addin folder and the dlls that it is using in the AntiVirus exclusion folder list, but still no result, I get the same init error.

Thanks
Gargi

Govert van Drimmelen

unread,
Apr 17, 2024, 5:46:25 AM4/17/24
to exce...@googlegroups.com

Hi Gargi,

 

> * What is the exact Excel-DNA version you are using? 30.22.1

This can’t be right.

 

Can you try a simple add-in with these project and code file?

 

TestExcelDna.csproj

 

 

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

 

  <PropertyGroup>

    <TargetFramework>net48</TargetFramework>

  </PropertyGroup>

 

  <ItemGroup>

    <PackageReference Include="ExcelDna.AddIn" Version="1.7.0" />

  </ItemGroup>

 

</Project>

 

 

Functions.cs

 

namespace TestExcelDna

{

    public class Functions

    {

        public static object SayHello(string name)

        {

            return $"Hello, {name} from TestExcelDna Add-In!";

        }

    }

}

 

 

If the simple add-in work, you can try to work your way towards the real add-in, to see what breaks.

 

-Govert

 

 

From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of Gargi Biswas
Sent: Wednesday, April 17, 2024 9:36 AM
To: Excel-DNA <exce...@googlegroups.com>
Subject: [ExcelDna] Re: Unable to launch Excel addin on Windows 11 PC

 

Hi Govert,

This is the error message that is cropping up. I checked the details that you mentioned as well. 

--
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/41f7c938-4314-4b9a-bac1-684e6ec07740n%40googlegroups.com.

image001.jpg

Gargi Biswas

unread,
Apr 17, 2024, 10:40:17 AM4/17/24
to exce...@googlegroups.com
Hello,

I saw a similar kind of Diagnostic error when I tinkered the <addin>.xll.config file locally. It got fixed when i corrected the error.
So I guess there is some config file initialization issue when I am trying to run it on Windows 11.

In this context, I wanted to understand the syntax of the <addin>.xll.config and the .dna file.
How will I know if my config file is being accessed or not?

Also, I see an attribute called Pack in the .dna file, what does that mean?

Can you please give me some pointers on this please.


Regards
Gargi Biswas


--

Govert van Drimmelen

unread,
Apr 17, 2024, 10:51:59 AM4/17/24
to exce...@googlegroups.com

Hi Gargi,

 

The <addin>.xll.config file is a normal .NET application config file.

The format is the same as any .NET application configuration file and not processed by Excel-DNA in a special way.

Under .NET Framework, Excel-DNA sets this file as the configuration file for the AppDomain that it creates.

(Under .NET 6+ the configuration file is not used.)

 

You might run into trouble if there are configuration types specified in the .config file which cannot be loaded successfully.

For example, if you were using a logging framework that was installed in the GAC on your Windows 10 machine, but is not present on the Windows 11 machine, you’d find this.

Also, some of the configuration type loading can be sensitive to the working directory, which can depend on how you load the add-in.

So that’s definitely one possible source of trouble.

Similar if you have some special Settings type that is not being picked up correctly.

 

You can look for other possible reasons for the error in the Google Group history: Search conversations (google.com)

It’s quite a general error.

Since your AutoOpen is not running, I’m guessing the problem happens when the AutoOpen is being JIT-compiled, which is the time when types are resolved and other assemblies found. You might move out pieces of your AutoOpen code to separate methods, to see if you can debug into the AutoOpen that way, and then see what method (and types referred to in that method) cause the crash.

 

The Pack attribute in the .dna file controls what references and assemblies are packed into the single-file .xll that we create during the Excel-DNA build.

These days, one no longer needs a .dna file in the project – the Excel-DNA build can create the .dna file in the output directory from the project configuration.

But if you have a working add-in project, you need not get rid of the .dna file – it should still work fine.

 

-Govert

 

From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of Gargi Biswas
Sent: Wednesday, April 17, 2024 4:40 PM
To: exce...@googlegroups.com
Subject: Re: [ExcelDna] Re: Unable to launch Excel addin on Windows 11 PC

 

Hello,

 

I saw a similar kind of Diagnostic error when I tinkered the <addin>.xll.config file locally. It got fixed when i corrected the error.

So I guess there is some config file initialization issue when I am trying to run it on Windows 11.

 

In this context, I wanted to understand the syntax of the <addin>.xll.config and the .dna file.

How will I know if my config file is being accessed or not?

 

Also, I see an attribute called Pack in the .dna file, what does that mean?

 

Can you please give me some pointers on this please.

 


Regards

Gargi Biswas

 

 

On Wed, Apr 17, 2024 at 1:05PM Gargi Biswas <garg...@gmail.com> wrote:

Hi Govert,

This is the error message that is cropping up. I checked the details that you mentioned as well. 

image001.jpg

Kedar Kulkarni

unread,
Apr 17, 2024, 12:06:43 PM4/17/24
to Excel-DNA
Hi Gargi, you may want to look at the samples repo to learn various techniques hands-on - https://github.com/Excel-DNA/Samples/.

there are some newer projects with .net core as well . 

Gargi Biswas

unread,
Apr 18, 2024, 2:09:57 AM4/18/24
to exce...@googlegroups.com
Hello Govert,

Thanks for the suggestions. I tried deleting everything inside AutoOpen() to see if the Diagnostic Error comes up.
It doesn't.

So, I included a few lines in AutoOpen() and then tried again. It crashed after that with the same Diagnostic error.

I was able to fetch the crash exception logs through the catch line handler.
My partial class that has the AutoOpen() overridden has some issues in its constructor.
Basically my addin class references functions from a separate dll, and the error log says that procedure from that dll cannot be imported.
It gives a System.FileLoadException.
image001 (1).png

I do have the dll present at the <addin>.dll location, but I still get this issue.

Do you have any suggestions on what might be the problem?


Regards
Gargi Biswas


Govert van Drimmelen

unread,
Apr 19, 2024, 7:59:30 AM4/19/24
to Excel-DNA
Hi Gargi,

This logs all the assembly load attempts and failures. 
You can get a log from both the working and problem machines and compare.

If there is a native code library involved, it might be that you have a 32-bit vs 64-bit issue between the machines.

Otherwise, there could be an assembly that is installed in the GAC on the working machine, and not present on the problem machine.

-Govert

Gargi Biswas

unread,
Apr 22, 2024, 5:31:37 AM4/22/24
to exce...@googlegroups.com
Hi Govert,

I used the fusion logger to see the AssemblyBinding failures and compare them, and the problem seems that one of my dlls is not getting loaded on the win11 machine.
It is a C++/CLI dll that refers native C++ dlls for execution.

Is there any issue with mixed assembly loading in excelDna?

It gives a System.FileLoadException: it is able to find the dll but not able to load.

Regards
Gargi Biswas


Govert van Drimmelen

unread,
Apr 22, 2024, 1:35:19 PM4/22/24
to Excel-DNA
Hi Gargi,

Perhaps the issue is in loading one of the native C++ dlls?
I'm not sure they will automatically be found in the same directory as the .xll.
Perhaps you have these in the Path on the working machine?

You can pre-load native libraries by calling LoadLibrary(...) with the full path.
As long as you make these calls before the mixed C++/CLI library loads, they will be found if they've already been loaded into the process.

None of this should be different under Windows 11 vs Windows 10, so you might look for other configuration differences between the machines.

-Govert

Gargi Biswas

unread,
Apr 23, 2024, 5:01:28 AM4/23/24
to exce...@googlegroups.com
Hi Govert,

Thanks for the helpful suggestions.

It seems LoadLibrary(...) belongs to the NativeLibrary namespace that only works on .NET.

I have my code compiled using .NET Framework, are you aware of any Library that i can use for explicit native dll loading here?
Or any way, that I can specify the order of dll loading using the .dna/.xll.config file?


Regards
Gargi Biswas


Govert van Drimmelen

unread,
Apr 23, 2024, 5:37:28 AM4/23/24
to exce...@googlegroups.com

Hi Gargi,

 

You can call LoadLibrary from the Win32 API by using a P/Invoke declaration.

 

-Govert

 

 

using System;

using System.ComponentModel;

using System.Runtime.InteropServices;

using ExcelDna.Integration;

 

namespace TestLoadLibrary

{

    public class AddIn : IExcelAddIn

    {

        [DllImport("kernel32.dll", SetLastError = true)]

        private static extern IntPtr LoadLibrary(string lpFileName);

 

        public void AutoOpen()

        {

            try

            {

                var addInDirectory = ExcelDnaUtil.XllPathInfo.DirectoryName;

                var libPath = System.IO.Path.Combine(addInDirectory, "ShaftKineticDll64.dll");

 

                // Load the dynamic library directly

                IntPtr handle = LoadLibrary(libPath);

 

                if (handle == IntPtr.Zero)

                {

                    int errorCode = Marshal.GetLastWin32Error();

                    throw new Win32Exception(errorCode);

                }

            }

            catch (Win32Exception wex)

            {

                XlCall.Excel(XlCall.xlcAlert, $"[0x{wex.HResult:X8}] {wex.Message}");

            }

            catch (Exception ex)

            {

                XlCall.Excel(XlCall.xlcAlert, ex.Message);

            }

        }

 

        public void AutoClose()

        {

        }

    }

}

 

 

From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of Gargi Biswas
Sent: Tuesday, April 23, 2024 11:01 AM
To: exce...@googlegroups.com
Subject: Re: [ExcelDna] Re: Unable to launch Excel addin on Windows 11 PC

 

Hi Govert,

I have tried repairing the MS-Office Suite as I found what others did on the web but in vain.

Gargi Biswas

unread,
Apr 24, 2024, 12:00:44 PM4/24/24
to exce...@googlegroups.com
Hi Govert, 

Thanks for the suggestion, I tried this one out and I see that the ExclDna, while loading, gives an error that the imported procedure couldn't be loaded.

I am using ExcelDna 0.34.6.1 version with my xll, I tried to upgrade this ExcelDna version to 1.1.0 for eg, but gives the below error, and fails to update.
image001 (2).png

I am trying to upgrade my ExcelDna version as my <addin>.dll is not able to reference this version of ExcelDna(I found out through AsmSpy), even though it is present in the addin exe folder.

Do you have any pointers on this please?
Like what version should I use or any config changes?

Regards
Gargi Biswas


Reply all
Reply to author
Forward
0 new messages