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
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.
--
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:05 PM 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/CAPOEJtpPQ5uJTPOjTMYBtqjK-tLJev%2BLZzZfXyWVsxDdjE3-sA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/6c13c371-c064-489d-a700-edc90c2b549en%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/21d0d04e-1ac3-4917-85b4-bdc919af6bb0n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/64e53c5d-1906-4c0d-94cd-1a5a57cc9cfen%40googlegroups.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.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/CAPOEJtq8wWfe3oRn4S6Vz-J9UaLofPYk%2BX00gSufhQUs2O%3DimA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/016001da9561%24d5d1e540%248175afc0%24%40gmail.com.