Can I add references at run-time

Add-in Express™ Support Service
That's what is more important than anything else

Can I add references at run-time
I want control whane the references are added for an optional feature 
Mike VE




Posts: 168
Joined: 2007-09-09
One of the feature of my add-in is printed calendar reports using Crystal Reports. It is valued by some customers but the majority do not use it. Installing the correct Crystal Reports Runtime as a prerequisite has various potential problems so I am looking for a way of only installing it if the user wants to use the print feature. The problem is that if the CR Runtime is not installed then in some circumstances the add-in will not load into Outlook - it is not just disabled, it is nowhere to be seen. This seems to be caused by the project's references to the Crystal Reports DLLs. Remove the references and it is fine.


Is there a way of leaving out the CR references but adding them at run time if needed, eg. user clicks button to print and, if necessary, the references are added and the CR runtime installed?


Thanks
Posted 23 Apr, 2019 03:27:33 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Hello Mike,

Check section How to Develop the Modular Architecture of your COM and XLL Add-in at https://www.add-in-express.com/docs/net-tips.php#modular-architecture. You can create an extra DLL that can be loaded only if you need this.


Andrei Smolin
Add-in Express Team Leader
Posted 23 Apr, 2019 03:47:30 Top
Mike VE




Posts: 168
Joined: 2007-09-09
Hi Andrei

Thanks for your reply. I've had a look at AddinAdditionalModule but I don't think it can do what I want - it seems designed just for UI elements. I want to load some of the references that are normally declared in the Addin's References section. I could put them all in a separate project but could I load that just on-demand at run-time?
Posted 23 Apr, 2019 06:35:05 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Mike,

I've had a look at AddinAdditionalModule but I don't think it can do what I want - it seems designed just for UI elements.


Yes, this module is designed for UI components but it does not matter in this case. The key point is that you can add this module to a separate project (class library) with its own references.

I could put them all in a separate project but could I load that just on-demand at run-time?


The section How to Develop the Modular Architecture that Andrei suggested contains an example of how to load an additional module (project with its own references) in the AddinInitialize event handler depending on a condition. Please consider this solution, hope it will suit your needs.


As for installing CR prerequisites at add-in's run-time, sorry, I have no idea on how to solve this. Probably you will have to install all prerequisites at installation time.
Posted 23 Apr, 2019 11:09:15 Top
Mike VE




Posts: 168
Joined: 2007-09-09
I put all the code related to Crystal Reports in a separate Project and remove the Crystal Reports from my main Addin project (though I did not need an AdxAdditionalModule as there were no extra UI elements). I thought I might have compile that new project as a separate, unreferenced, DLL and the use Reflection to load it at run-time. However, it turned out that just putting the CR related code in a separate project within the solution did the trick of avoiding problem in loading the addin into Outlook.


Now if a user clicks the UI button to print the resulting code will give an error if CR is not installed. My app then uses Outlook bitness to determine which version of CR Runtime to download and install.


Just for the record I found that using the Crystal Reports Prerequisite for the setup project caused more problems than it solved as it selected the version of CR based on Windows bitness whereas only the version matching Outlook's bitness worked.


Thanks for the help guys.
Posted 24 Apr, 2019 16:07:50 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
That's great! Thank you for the Crystal Reports Prerequisite bit!


Andrei Smolin
Add-in Express Team Leader
Posted 25 Apr, 2019 01:40:01 Top