Sometimes when working with office Interop assemblies the above mentioned error occurs. I had also got the same when using Microsoft Excel interop assembly and adding its reference in my ASP.NET application.
The problem is that by default when Microsoft Excel is used as a COM object then it can only be activated by the following accounts:
And when you are running your web application on windows server 2003, it is running under ASPNET account.
The way to resolve this issue is to edit the DCOM configuration settings for Microsoft Excel Application object.
- Go to Start -> Run.
- Type DCOMCNFG. (This will load the "Component Services")
- Go to Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application.
- Right click and select Properties.
- Select the Security tab.
Press Add button to select the "Network Service" account.
Click the OK button, and then test your application, it should work fine now.