Reputation: 93
When I add Microsoft.Office.Interop.Word in my references and using in my class I get some strange error and I am not able to solve it. I have attached a photo.
It says:
Interop type 'Microsoft.Office.Interop.Word.ApplicationClass' cannot be embedded. Use the applicable interface instead.
How to resolve this?
Upvotes: -1
Views: 1373
Reputation: 157136
You can't (or at least shouldn't) instantiate the class itself. You should ways use the interface. Okay, you can't create a new instance of an interface, but since the interface has the CoClass
attribute on it, it can. Behind the scenes there is some magic going on.
So this code is fine, although it seems weird to create an instance of an interface:
Application application = new Application();
Also, you shouldn't use Office interop in ASP.NET, as per Microsofts guidelines in Considerations for server-side Automation of Office.
Upvotes: 2
Reputation: 7490
Remove Class
suffix, just use
Application applicationclass = new Application();
OR
Open assembly properties in VS and set "Embed Interop Types" to "False".
Upvotes: 4