views:

49

answers:

1

So I wrote a method in my company's product a year and a half ago that makes use of Excel 2007's COM automation to export data, only now I'm finding that it's no longer working on machines in the office.

I tested the functionality of the method on my own machine and got the same result.

Digging deeper, I found that when I get as far as

var excel = Excel.Application

If I add a watch on the excel object, I see that every property throws a cast exception.

After doing some research, I saw something about registry keys that can interfere with automation. I managed to dig through and delete a registry key:

HKEY_CLASSES_ROOT\TypeLib{00020813-0000-0000-C000-000000000046}\1.7

With the following string value defined within:

"PrimaryInteropAssemblyName"="Microsoft.Office.Interop.Excel, Version=14.0.0.0

I then ran the same piece of code again, only this time it ran perfectly fine.

Other machines in the office I've tested the application on have had the same error, only I haven't been able to fix them in the same way.

Has anyone else encountered this before?
Thanks

+1  A: 

Version 14 of Office is Office 2010, so I assume that your office has upgraded from 2007 to 2010.

Now, if your computer is a developer machine then I would expect that you have the Microsoft.Office.Interop.Excel, Version=14.0.0.0 assembly on your computer and so your fix works.

However, I guess that the other machines in the office had your code deployed to them so they would have the Microsoft.Office.Interop.Excel, Version=12.0.0.0 assembly, but not the Microsoft.Office.Interop.Excel, Version=14.0.0.0 deployed.

If I were you, I'd check that first.

It may have also been useful to describe the actual error you got in your question, but hopefully my answer helps.

Enigmativity
No, I don't have any Office 2010 products installed on my machine, aside from SharePoint Designer, maybe. The error that occurs is thrown by COM - DISP_E_MEMBERNOTFOUND. When debugging, it seems to manifest itself as an invalid cast exception.
stevenroberts
@`stevenroberts` - In that case the Office 14 interop assembly must have been installed with Visual Studio. Afterall, if you didn't explicitly install the interop assembly it must have come from somewhere and it's still likely that the client machines don't have it. Have you checked them?
Enigmativity