Programmatically Add Reference Com Component into C# Project?

A

Adam Right

Hi,

I am developing a project which uses "Microsoft Word Interop". There may be
a case in which the end-user may not have Microsoft Office or Office
Interops. So i do not want to add a com reference into my project from the
Solution Explorer by right-click "Add reference". I do want to add com
reference when the user loads the page that is going to show a "Microsoft
Word" document. In this case, while the page is loading, i can check that
the user has the interops or not. If not, i am going to show a message box
including the error message.

Programmatically adding com refernce is possible?or not? Thanks...
 
M

Marina

Adding a reference is only relevant at compile time. It is so your code can
compile. Adding references is a visual studio concept, not deployment.

Either your code can compile, or it can't. By the time the end user gets
it, it's already compiled.

After deployment, if your DLL needs a particular component, and can't find
it, then it's too late, and you get an error.
 
G

gmiley

You could probably use Reflection to bypass the functionality of some
things based on availablily of libraries on an outside users PC.

In my experience Reflection can add some overhead to your applications,
but can be used to make more addaptible to its surroundings.
Pseudo-polymorphic if you will.

Making use of Attributes on your classes will assist in using
Reflection to use different methods in place of ones that may be
missing required resources.
 
B

Boni

Dear Sir,
there is no difference for end user what is added to your project as
reference.
Important is, how the referenced types are resolved at run time. So if user
has no word, then the first fuction, which uses classes from this interop
will throw an exception.
Just catch this exception or don't call this function, if word is not there.
Hope it makes sence. You might want to read in MSDN how types are resolved
(keyword reflection,
AssemblyResolve, ResolveEventHandler ...).

Best regards,
Boni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top