Exposed Types from ExternalLibrary not available

Jun 30, 2011 at 12:07 AM

I have 64-bit office, the 64 bit version of Excel DNA, and this file:

<DnaLibrary RuntimeVersion="v4.0" Language="CS">
    <ExternalLibrary Path="BackstopConnector.dll" />
    <![CDATA[

    using ExcelDna.Integration;
    using System.Data;
    using BackstopConnector;

   ...

</DnaLibrary>

If I misname the library in ExternalLibrary - I get a loud complaint, so I know the DLL is located. However the public types and namespaces in it create errors when referenced in the .dna file. For example the dll file has one class:

using BackstopConnector.BackstopReportDirectoryService_1_0;

namespace BackstopConnector {
  public class ReportList {

  }

}

 

yet referring to the namespace in the .dna file causes: There were errors when compiling project:
c:\Users\dradcliffe\AppData\Local\Temp\kzqrdh5c.0.cs(3,11) : error CS0246: The type or namespace name 'BackstopConnector' could not be found (are you missing a using directive or an assembly reference?)

I don't see what I'm missing - could the fact that the referred-to assembly talks to web services have anything to do with it ?

Thanks for help..

Dean

Coordinator
Jun 30, 2011 at 8:43 AM

Hi Dean,

If your source code is directly in the .dna file, and that code should Reference another assmbly when compiling, you need a <Reference> tag for the other assembly. The <ExternalLibrary> tag is when you want to export the functions from the other library to Excel.

So I think you can try:

<DnaLibrary RuntimeVersion="v4.0" Language="CS">
    <Reference Path="BackstopConnector.dll" />
    <![CDATA[

    using ExcelDna.Integration;
    using System.Data;
    using BackstopConnector;

   ...

</DnaLibrary>

There might be more issues:

  • All the assemblies you want to load into the 64-bit Excel must be built for "x64" or "All CPU" targets.
  • You might need additional <Reference> tags for dependent assemblies that are loaded by BackstopConnector.dll (which are not in the GAC). Otherwise the assembly loader will look for them only in the GAC and in the process directory (where Excel.exe lives). Excel-DNA tries to help with the reference resolution though, so you can experiment a bit.

Regards,

Govert

Jun 30, 2011 at 5:30 PM

Govert,

    Yes, thank you for clearing up that misunderstanding - with that change it works ! I do have some dependent assemblies, but they all seem to get loaded fine, at least on the development machine. Any suggestions for deployment-time placement ? Are there any nice tutorials on creating setups for these, especially if they'll install without administrator privileges ?

Dean

Coordinator
Jun 30, 2011 at 9:22 PM

Hi Dean,

My suggestion for 'installing' is to use ExcelDnaPack to put everything you need into a single .xll file. Then your users just copy it anywhere they want, and add it to Excel through the add-ins dialog (press Alt+t, i). It feels like cheating but works very well.

There are other options, but this would certainly be the best start.

To use ExcelDnaPack you just set

    <Reference Path="..." Pack="true" />

and

    <ExternalLibrary Path="..." Pack="true" />

and then run

    ExcelDnaPack.exe MyAddIn.dna

This gives you a MyAddIn-packed.xll which needs no other files, and no admin privileges to run, install or to add as an add-in in Excel.

Other options;

* You can add a self-registering bit in the AutoOpen. Then users only have to open your .xll by double-clicking, and it will stay added in for future sessions.

* Some developers try to make more sophisticated setups for their add-ins. I think it's mad and can't really help, but you don't have to do much more then copy the files and run some script to register.

* Making a setup for "All Users" is nearly impossible.

* Some developers make their own update manager tool (as another add-in) that can dynamically look for and load new versions of the add-in.

-Govert

Oct 17, 2011 at 4:18 PM
Edited Oct 17, 2011 at 4:24 PM

Hi Govert,

I am new to using ExcelDnaPack.exe and ExcelDna in general.  I want to pack all of my resource files into one XLL for deployment.

I want to pack a PDF and an XML config file along with the DLL library into the XLL.

My DNA file looks like this:

<DnaLibrary Name="Test Project" RuntimeVersion="v4.0">
 <ExternalLibrary Path="TestProject.dll" Pack="true" />
 <Reference Path="HelpGuide.pdf" Pack="true" />
 <Reference Path="servers.xml" Pack="true" />
</DnaLibrary>

However, the TestProject-packed.xll file is the same size as the TestProject.xll file.  Since the PDF file is 294k in size I can see that the pack has not worked as I would have expected.  How do I get this to work?  I am working in 32-bit Windows XP.

Your assistance would be much appreciated.

Kind Regards
Jon

Coordinator
Oct 17, 2011 at 4:33 PM

Hi Jon,

You should have a look at the output from ExcelDnaPack. That could give a clue about whether the packing is resolving the other files correctly. The packing does some compression, including of an assembly that is already in the .xll, so the size would not be a great indicator.

I'm not sure how you'd retrieve and use those other packed resources - you might be better off adding the .pdf and .xml files as .NET resources in your TestProject.dll. Then you might be able to use them via the usual resource access.

Regards,

Govert

Oct 17, 2011 at 11:03 PM

HI Govert

Thanks for the speedy response.


Do you just mean the output it displays at the command prompt or does ExcelDnaPack create a log file somewhere? 

Kind Regards
Jon 

Coordinator
Oct 17, 2011 at 11:06 PM
Edited Oct 17, 2011 at 11:07 PM

Hi Jon,

The output from the command line shows what the packing has done, and will show any errors (or an exception trace if things really go wrong).

-Govert

Oct 19, 2011 at 9:59 AM

Hi Govert

Thanks for that.  I went with having the PDF and XML config as embedded resources in the end.

Another question though: You mentioned above about adding a self-registering bit in AutoOpen().  How do I go about doing that?  I want to make installation as simple as possible,

Kind Regards
Jon