Greg Reddick is a noted speaker, author, and software engineer. This blog covers all aspects of programming, particularly for Windows, and other related topics.

2013-12-23

Excel Automation Add-In Won't Register

I spent a few hours trying to figure out why my C# Excel Automation Add-In wouldn't register. Every time I tried to add it, it complained that it wasn't an Automation Add-In. Everything looked right. All the code matched the examples from elsewhere, and the registry entries looked perfect, so why was it failing? I slept on it, and woke up with the answer. (Yes, I debug best in my sleep.) The name was too long!

It turns out that the entire name for the class must be 39 characters or less. This includes the namespace. The only punctuation allowed is a period. Thus

How did I know? Well, I have run into stupid arbitrarily short name lengths before in Windows, and it connected for me that this might be one of those. After doing some research I found that the limitation is described in the ProgID attribute documentation.

Another problem I ran into...the AddIns.Add and AddIn2.Add methods were failing with the "Add method of the AddIn class failed" error. I was passing the file name of my add-in DLL. However, you can only pass the file names of XLAM add-ins using the file name. For DLL add-ins, you must pass the class name or ProgID, that you assigned using the techniques I described above. The DLL must already be registered with Windows, which should have been performed by the Install program for the DLL, or by using the regasm command line tool.