views:

225

answers:

2

Hi All,
I have created a windows application which makes use of Office.dll and powerpoint dll of Microsoft office 2003. At design time, when I am adding referrence of these dlls to my project it refers following path;
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.PowerPoint\
The application runs perfect on the machine where it is developed, but when I am trying to run it on other machine it fails. The exception it is throwing is;
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException I tried to locate the above path on my test machine, but I am surprised that, though office 2003 and 2007 is installed (2 different machines), this folder is not present over there.
Can anybody help me resolving this issue?
Thanks in advance.

A: 

The interop dll you are looking for is installled on your deevelopment machine in the GAC. As such it is not a part of the standard deployment. You need to copy it over by hand.

Another option (and may be a cleaner one) would be to run the Office installation on the target machine and let it install all what's necessary. Just make sure that you selected proper options

mfeingold
I have tried PIA for both office versions, it worked for office 2007, but the issue still exist for office 2003. I guess, I have installed office 2003 in typical mode.
Vijay Balkawade
+1  A: 

1.There is an Office 2003 Primary Interop Assemblies (PIA) redistributable is a Microsoft Windows Installer package that contains the Primary Interop Assemblies for Microsoft Office 2003 products you can get it from here it includes an assembly you need

2.You can set true to the "Copy Local" key for this assembly in your project references properties, in this case it would be copied into the output folder of your project

3.You don't really need it to work with MS Office applications, though it makes it easier. Below is an example of how you can open a presentation without interop classes

Type officeType = Type.GetTypeFromProgID("PowerPoint.Application");
object officeInstance = Activator.CreateInstance(officeType);
// set visible
object value = -1;
officeType.InvokeMember("Visible", BindingFlags.SetProperty, null, officeInstance, new object[] { value });
// open presenation
object objTrue = -1;
object objFalse = 0;
object fileNameObj = presentation_file_name;
object documents = officeType.InvokeMember("Presentations", BindingFlags.GetProperty, null, officeInstance, null);
documents.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, documents, new object[] { fileNameObj, objTrue, objFalse, objTrue });

didn't test this exact one, but smth like this works fine for me, regards

serge_gubenko
Thanks buddy. Loading assembly dynamically, works fine. But my problem is, on target machine I don't have GAC folder.If I install PIA it works with both office version with Reflection. I don't want to distribute Microsoft assemblies with my application as it may cause potential threat.And installing PIA on every target machine is not feasible.
Vijay Balkawade
I guess you're in the dead end here; there are no needed assemblies in GAC folders on target machines and you don't want\can't install them, so #1 doesn't work. You also don't want to bundle interop assemblies with your application(s); this means #2 doesn't apply either.
serge_gubenko