Problem with dynamic DnaLibrary path of Excel DNA

Jul 4, 2014 at 7:24 AM
.dna file contains the following data:

<DnaLibrary Name="First Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="MyLibrary.dll" Pack = "true"/>

It works localy.
But when I create a package, and run on other PC, it throws the following error:

External library could not be registered - Path: MyLibrary.dll
Error: The library could not be found at this location.
If I mention full path, then I have to put all the required files on the same path , where I want to run this .xll file.
How can I resolve this? So that I do not require to mention the full path and it should work on any PC.
Jul 4, 2014 at 9:35 AM

Did you use the NuGet package to build your add-in?
If so, you can check the output directory of your project. You'll find something like:
  • MyLibrary.dll
  • MyLibrary-AddIn.dna
  • MyLibrary-AddIn.xll
  • MyLibrary-AddIn-packed.xll
  • ...etc.
If you copy only MyLibrary-AddIn-packed.xll to another machine, it should work. This is the packed add-in (and you can freely rename it to anything.xll).

Alternatively, you can copy these three files:
  • MyLibrary.dll
  • MyLibrary-AddIn.dna
  • MyLibrary-AddIn.xll
    to another machine and it should work.
If that does not work, perhaps something went wrong in the packing. You can paste here the output from the ExcelDnaPack.exe bein run (you'll see it in the output window when rebuilding your project).

Jul 4, 2014 at 10:45 AM
Hello ,


No, I did not use NuGet package to build add-in
I created one excel dna with simple add(a,b) function , which i am able to access in excel with above files.
I want to use this add-in for another add-in in which i make ribbon button ,
on its click event i am opening excel sheet in which i had given some inputs.
in same excel i am calling dna add() function. for which i need to register .xll programmatically.
In this case i i am giving hard coded path for .xll.

It works locally but not on other machine.
I want to run this "Ribbon button add-in" on any machine.
Jul 4, 2014 at 11:02 AM
Edited Jul 4, 2014 at 11:03 AM
OK - so you always copy the three files .xll, .dll and .dna to the other machine and keep them together?

Are you using Application.RegisterXLL to load the other add-in?

Anyway - if you use a relative path like <ExternalLibrary Path="MyLibrary.dll" /> and you get the message Error: The library could not be found at this location., then it really means that MyLibrary.dll cannot be found next to the .xll file.

Are you perhaps confusing different copies of the .xll file? I also suspect that you can't load "MyAddIn.xll" from a different location with RegisterXLL after "MyAddIn.xll" has been loaded once.

Jul 8, 2014 at 5:18 AM
Hello Govert ,
Thank You !

I merge both projects in one class library in excel dna only.
I created ribbon button with .dna file. and excel methods in .class library in same solution.
it works fine !