- Posted by Shay Friedman on January 5, 2011
Lately I needed to write a small “add-in” for Excel that adds a function written in C# (another case of “when your 4 years of office add-in development experience comes back to haunt you”). Before going ahead with that I searched the web for a quick how-to and ran into this old but still relevant blog post by Eric Carter.
I did everything Eric had described, but every time I tried to add the add-in through the Automation Servers dialog I just couldn’t find it in the list. Trying to locate the file through the Browse button resulted in the next window:
Such a sweet little message that tells you so much and at the same time tells you nothing at all. How can’t you love developing for Office?
After a couple of hours fighting it with everything I knew (run as admin, installing through a setup project, rewriting everything and more) just when I was ready to throw the laptop out the window and wait for Chrome OS to come out, the brilliant mind of Eran Stiller came up with the question – “maybe it’s related to some 64-32 bit stuff”.
Facepalm. Head-to-desk. Facepalm again. Of course it was related!
As you can understand, I have Excel 2010 64bit installed on my machine. And that’s the root of all my problems. Yes, each and every single one of them.
Anyway, To get the addin working on my machine I had to manually register the DLL using the .NET framework’s 64bit regasm utility. If you also have the same problem, follow the next steps to solve it:
- Follow all the steps in Eric Carter’s blog post.
- Open the project’s properties and uncheck the “Register for COM Interop” checkbox (I actually don’t think it really matters but just in case).
- Rebuild the project.
- Open cmd (open Start->Run, type “cmd” and hit Enter).
- Navigate to %windir%\Microsoft.NET\Framework64\v4.0.30319
- Run: regasm /codebase <path_to_dll>\MyAssembly.dll
Pay attention to the /codebase switch – without it, it won’t work!
That’s it, you’re done. Your command prompt would look similar to that:
[Notice that you’ll get a warning here that the assembly is not signed. If you’re writing a real product, make sure you sign it!]
After that, open Excel and add your DLL again (according to the instructions in Eric’s post). After you do that, try using your functions!
I’m adding my sample project here (which works for me) and its output assembly so you can play with it:
Let me know if something isn’t clear or doesn’t work for you.
All the best,