Friday, February 06, 2009

Cannot find "managed coclass wrapper"?

I'm doing a little bit of office automation. I'm writing a C# program to automatically create a Microsoft PowerPoint presentation (actually it's more of a slide show).

I've got the PowerPoint interop library referenced and imported properly...

using Powerpoint = Microsoft.Office.Interop.PowerPoint;

and declared and instantiated the PowerPoint application as required...

Powerpoint.Application app = new Powerpoint.Application();

But Visual Studio 2008 seems on occasion to dislike this, and gives me an error on the line, saying:

The managed coclass wrapper class 'Dummy type name' for interface 'Microsoft.Office.Interop.PowerPoint.Application' cannot be found (are you missing an assembly reference?)

But the thing compiles. The project builds. The solution builds. I can create the installer. The installer installs. It's apparently just the IDE that is as confused as I get when I watch an episode of "Lost".

So the issue apparently is that I'm trying to create a new instance of an interface. The interface happens to be marked with a [CoClass()] attribute, and the compiler is smart enough to know that it needs to create a dummy wrapper for the instantiation, but apparently VS2008 didn't read all of the memos. So my workaround is to change my code slightly and instantiate the actual implementation class pointed to by the interface...

Powerpoint.Application app = new Powerpoint.ApplicationClass();

And the thing compiles. The project builds. The solution builds. I can create the installer. The installer installs. And the IDE doesn't waste any CPU cycles telling me about a problem that doesn't really exist.

1 comment:

TorrentGuru said...

I had the same issue with automation of Outlook 07.
However, my implementation is a bit different:
Outlook._Application oApp = new Outlook.ApplicationClass();

Thanks again!