tags:

views:

452

answers:

1

Hi,

I am using .net Primary Interoperability Assembly for Excel in my code. But, the application can be run on machine which doesn't have .net PIA for Excel installed. I want to give an error message if it is not installed

Even though I am checking in GAC, to see if PIA is installed and only if it is present I am using Microsoft.Office.Interop.Excel related code. I am getting an error.

My problem is - I am getting error which is - Unhandled Exception - can't find could not load file or assembly Microsoft.Office.Interop.Excel

Any solution?

Thanks in advance!

A: 

I guess System.Type.GetTypeFromProgID("Excel.Application",true); method will throw exception if Excel is not present. You can use a try catch block and verify.

danish
You probably would get `System.__ComObject` as the type if you don't have the interop installed. There is exception thrown.
0xA3
Yes that is what the check is for.
danish
Sorry, there was a 'no' missing in my comment. It should have read "There is **no** exception thrown."
0xA3
My mistake. That was the wrong overload. Corrected it. Now this method call will throw exception if mentioned application is not installed.
danish
Hello danish, Thanks for your reply.I tried the method you suggested, but that doesnt work. If the machine where I run this program doesnt have PIA for excel installed then the it throws System.IO.FileNotFoundExceltion.
raghvendra
That is what the check is. Call the method. If you get exception, this means Excel is not installed so display a message or something. If it doesn't throws exception, carry on with the task.
danish