Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

using my DLLs inside the ExcelDna dll

85 views
Skip to first unread message

enrico bortoluzzi

unread,
Dec 27, 2024, 4:49:56 AM12/27/24
to Excel-DNA
Hello,
It is a while that I am looking to retire my old VBA library of functions with my C# dlls without the COM
So I am interested in the ExcelDna and I create successfully my first simple ExcelDna class library and it works fine in debug with breakpoints

using FramesCs;
using ExcelDna.Integration;

public static class MyFunctions
{
  [ExcelFunction(Description = "My first .NET function")]
  public static string SayHello(string name)
  {
    return "Hello " + name;
  }

  [ExcelFunction(Description = "Split string", Category = "STRING")]
  public static object[] StringSplit([ExcelArgument(Name = "TEXT", Description = "text to split")] string text)
  {
    //var frm = new Frame(Orient.RPY, 10.2, 3.5);
    return text.Split(' ').ToArray();
  }
}

then I tried do add one of my dlls, the FrameCs.dll to the solution adding a reference and the
using FramesCs;
 statement
No error while compiling even with the uncommented
var frm = new Frame(Orient.RPY, 10.2, 3.5);
but in the excel the stringsplit fails, while if at runtime I comment the line and apply hot reload 
   //var frm = new Frame(Orient.RPY, 10.2, 3.5);
everything works fine

I hope there is some setting that can allow me to use for my dlls by referencing them
I need them just internal computation no to interact with excel

Immagine 2024-12-27 101604.png


Govert van Drimmelen

unread,
Dec 28, 2024, 7:44:42 AM12/28/24
to exce...@googlegroups.com

Hi Enrico,

 

For the case where you’re debugging the add-in from Visual Studio, it should just work fine with the extra dependency.

Can you see that it is copied correctly to the output directory?

 

For the ‘packed’ version of the add-in (which you see in the ‘publish’ subdirectory of the output) you might need an extra step.

If you are targeting .NET Framework 4.x, you need to add an entry in the .csproj project file like

 

<PropertyGroup>

    <ExcelAddInInclude>MyLibrary.dll</ExcelAddInInclude>

</PropertyGroup>

 

(The property is a semicolon separated list of references.)

 

If you are targeting .NET core (.NET 6+) this should not be needed – we pick up the dependencies from the .deps.json file automatically.

 

If it’s still not working, check in the debug output is you can see any load errors there.

 

-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 visit https://groups.google.com/d/msgid/exceldna/d83832b1-02c2-4660-a02a-616fbd8895edn%40googlegroups.com.

image001.png

enrico bortoluzzi

unread,
Dec 29, 2024, 4:07:46 AM12/29/24
to Excel-DNA
Hi Govert,

thanks for your time and hints.

Yes my dll is a class library .NET framework targetting Framework 4.7.2 and using Accord.NET dlls as references

Immagine 2024-12-27 101604.png

To be sure I added all of the dlls
  <PropertyGroup>
    <TargetFramework>net6.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <ExcelAddInInclude>FramesCs.dll;Accord.dll;Accord.Math.Core.dll;Accord.Math.dll</ExcelAddInInclude>
 </PropertyGroup>

then I checked the target build folder
Immagine 2024-12-29 095008.png

Still I got problems and the VS debug was not working anymore, so I reset my VS2022 (repair and reset all setting to the default, VS2022 is new to me I was using VS2019 up to last week) and restart from scratch with your suggestions

This time debug it is working also for my dll, did not check the publish.
However this time I got an error about the 

[ExcelArgument(Name = "TEXT", Description = "text to split")]

which is supported on windows 7.0 and above while following your youtube I am using , so I commented it

    <TargetFramework>net6.0-windows</TargetFramework>

Govert van Drimmelen

unread,
Dec 30, 2024, 10:05:39 PM12/30/24
to exce...@googlegroups.com

You can change your target framework to "net472" or "net48" to target .NET Framework if you'd like.

Error you describe might be if you target "net6.0" instead of "net6.0-windows”. That's what the VS project template starts with, but it then doesn't know what version of the Excel-DNA assembly to use until  you add the windows specifier.

-Govert


Reply all
Reply to author
Forward
0 new messages