Hi Govert
I tested the DNA files supplied in this thread, as you suggested, and they worked as advertised. They load and unload the XLL without errors. I am using ExcelDNA2.9 with Excel 2003. I can also report that it worked with a "packed" Xll too.
The loader works in both the DNA example and the C# module.
When I take the DNA code and put it into VS2008 as C# code, build a DLL, have a same named DNA and XLL file, I still get a exception thrown on this call.
object removeId = XlCall.Excel(XlCall.xlfRegister, name, "xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2);
my DNA file is simple.
<DnaLibrary>
<ExternalLibrary Path=".\HostAddIn.dll" Pack="true" />
</DnaLibrary>
One observation :
After the first exception is caught, if I rerun the XLL unloader code in the same process, it unloads the XLL without error, if I set a break point on this call and try to step through the unload calls, it throws an exception every time. In either case, the first time I call the unload function, it throws an exception on the call above.
Here is the C# code.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace HostAddIn
{
using ExcelDna.Integration;
public class HostXLL
{
public static object registerId;
private const String addInToLoad = @"C:\work\AXLL\bin\Debug\AXLL-packed.xll";
[ExcelCommand(MenuName = "AddinHost", MenuText = "Load Addin")]
public static void LoadAddin()
{
XlCall.XlReturn result = XlCall.TryExcel(XlCall.xlfRegister, out registerId, addInToLoad);
}
[ExcelCommand(MenuName = "AddinHost", MenuText = "Unload Addin")]
public static void UnloadAddin()
{
string name = @"C:\work\AXLL\bin\Debug\AXLL-packed.xll";
MessageBox.Show("About to call xlAutoRemove.");
try
{
object removeId = XlCall.Excel(XlCall.xlfRegister, name, "xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2);
object removeResult = XlCall.Excel(XlCall.xlfCall, removeId);
object removeUnregister = XlCall.Excel(XlCall.xlfUnregister, removeId);
object success = XlCall.Excel(XlCall.xlfUnregister, registerId);
MessageBox.Show("Result of Unregister: " + success.ToString());
}
catch (Exception xllErr)
{
string errMsg = xllErr.Message;
errMsg += (xllErr.InnerException != null ? Environment.NewLine + xllErr.InnerException.Message : Environment.NewLine + " No inner message ");
errMsg += (!string.IsNullOrEmpty(xllErr.StackTrace) ? Environment.NewLine + xllErr.StackTrace : Environment.NewLine + " No stack message ");
MessageBox.Show(errMsg);
}
}
}
public static class MyFunctions
{
public static string AddinHostTestFunction()
{
return "Hello from the add-in host!";
}
[ExcelCommand(MenuName = "AddinHost", MenuText = "Say Hello!")]
public static void AddIn()
{
MessageBox.Show("Hello from the add-in host!");
}
}
}
The error message thrown :
Exception of type 'ExcelDna.Integration.XlCallException' was thrown.
No inner message
at ExcelDna.Integration.XlCall.Excel(Int32 xlFunction, Object[] parameters)
at HostAddIn.HostXLL.UnloadAddin() in C:\Host\HostAddIn\HostAddIn.cs:line 30
Looking for suggestions or another path I can try to determine what is causing this error.
Thanks
Rob D.