AddInInitialize is not being called.

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

AddInInitialize is not being called.
Where to call initialization best? 
AppDev




Posts: 26
Joined: 2016-06-22
Hello Andrei,

I just wrote to ask your professional advice.

With the help of a client with a machine where this issue can be reproduced, we have found out that the AddIniInitialize() is never triggered/called in some machines. Because of this, our addin does not startup correctly for our end user and would never work for our clients. I tried simulating it by removing the initialization forcibly in code and true enough, the bug was reproduced.

That being said, I researched in the forums and found the following link :

https://www.add-in-express.com/forum/read.php?FID=5&TID=9259

In that link, there are three better points to call the initialization. Of the three which do you think is best? Which of these events get triggered ALWAYS, gets called first and gets called at least once? For now, I am thinking of moving the initialization sequence to the OnRibbonBeforeCreate() event. What do you think?

Thank you very much. Stay awesome!
Posted 20 Jan, 2020 20:42:10 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello,

AppDev writes:
AddIniInitialize() is never triggered/called in some machines


This means the add-in doesn't load on these machines at all. There are many possible reasons for an add-in not to load. This occurs if the add-in raises an exception at startup; say, this will be the case if some files aren't deployed, or wrong versions of the files are deployed, etc. But... Such a scenario creates an adxloader.log (if adxloader.dll.manifest specifies creating it) as opposed to no adxloader.log is created/updated if the add-in doesn't load because it is disabled, etc. If adxloader.log isn't created/updated in your case, check section Troubleshooting; see the PDF file in the folder {Add-in Express}\Docs on your development PC.

AppDev writes:
I researched in the forums and found the following link


That page discusses the order of events; the customer describes how AddIniInitialize occurs after OnRibbonBeforeCreate. One of these events occurs first. The actual order depends on the host application used, application version and the way you start the application.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jan, 2020 03:53:53 Top
AppDev




Posts: 26
Joined: 2016-06-22
Hi andrei,

I think that the addin was loaded correctly in those machines. I have seen outlook list our addin correctly with the right location too. Moreover, the addins constructor was executed and finished successfully. Any form of crash within that piece of code would have triggered a log in our error logs. Just to make sure, here is a copy of the adxloader logs content :


Add-in Express Loader Log File: 01/20/2020 10:47:23:770

Startup directory: C:Program Files (x86)KnowBe4Phish Alert
Loader version: 9.4.4644.0
Operating System: Microsoft Windows 10 Professional (build 18362), 64-bit
Process Owner: User
Command Line: "C:Program Files (x86)Microsoft Office
ootOffice16OUTLOOK.EXE" 
Run 'As Administrator': No
Process Elevated: No
Integrity Level: Medium
UAC (User Account Control): On
------------------------------------------------------------------------
10:47:23:773 7564 8404 Start.
10:47:23:774 7564 8404 The host's version is 16.0.12325.20298
10:47:23:774 7564 8404 Creating a new instance of the add-in loader.
10:47:23:774 7564 8404 Loading mscoree.dll
10:47:23:775 7564 8404 INFO: Assembly codebase - C:Program Files (x86)KnowBe4Phish AlertPhishAlert.dll.
10:47:23:776 7564 8404 INFO: Assembly version - 1.4.23.0.
10:47:23:776 7564 8404 Success.
10:47:23:776 7564 8404 Loading the configuration from the system registry.
10:47:23:777 7564 8404 Getting the latest CLR version.
10:47:23:778 7564 8404 The latest CLR version is 'v4.0.30319'.
10:47:23:778 7564 8404 The configuration has been loaded successfully.
10:47:23:778 7564 8404     Runtime version: v4.0.30319.
10:47:23:778 7564 8404     Assembly name: PhishAlert, PublicKeyToken=84DA3DAEA3332697.
10:47:23:778 7564 8404     Class name: KnowBe4ReportPhishing.AddinModule.
10:47:23:778 7564 8404     Registry key: CLSID{C6706A1B-6BBA-4E58-A82D-C443F328D9C7}.
10:47:23:850 7564 8404 Attempting to create a new instance of the managed add-in class: CLR - v4.0.30319
10:47:23:850 7564 8404 Loading CLR: v4.0.30319.
10:47:23:850 7564 8404 Calling CLRCreateInstance method.
10:47:23:850 7564 8404 Success.
10:47:23:850 7564 8404 Calling GetRuntime method.
10:47:23:850 7564 8404 Success.
10:47:23:850 7564 8404 Checking if the hosting API of .NET Framework v4.0 beta is installed.
10:47:23:870 7564 8404 The hosting API is up to date.
10:47:23:870 7564 8404 Calling SetDefaultStartupFlags method.
10:47:23:870 7564 8404 Success.
10:47:23:870 7564 8404 Calling GetInterface method for the CorRuntimeHost interface.
10:47:23:870 7564 8404 Success.
10:47:23:870 7564 8404 Starting CLR...
10:47:23:870 7564 8404 Success.
10:47:23:870 7564 8404 Getting the CLR version.
10:47:23:870 7564 8404 The CLR v4.0.30319 has been initialized successfully.
10:47:23:940 7564 8404 Creating a new domain setup.
10:47:23:942 7564 8404 Success.
10:47:23:943 7564 8404 Getting the add-in directory.
10:47:23:943 7564 8404 Success. The directory is 'C:Program Files (x86)KnowBe4Phish Alert'
10:47:23:945 7564 8404 The 'shadow copy' is disabled.
10:47:23:945 7564 8404 Creating a new application domain.
10:47:23:954 7564 8404 Success.
10:47:23:954 7564 8404 Creating an instance of the managed class. Assembly identity: 'PhishAlert, PublicKeyToken=84DA3DAEA3332697'
10:47:24:133 7564 8404 Success.
10:47:24:133 7564 8404 Unwrapping the managed class.
10:47:24:143 7564 8404 Success.
10:47:24:143 7564 8404 Querying the add-in extensibility.
10:47:24:144 7564 8404 Success.
10:47:24:144 7564 8404 Querying the custom task panes.
10:47:24:144 7564 8404 Success.
10:47:24:144 7564 8404 Querying the ribbon extensibility.
10:47:24:144 7564 8404 Success.
10:47:24:144 7564 8404 Querying the form regions.
10:47:24:144 7564 8404 Success.
10:47:24:144 7564 8404 Querying the encryption provider.
10:47:24:145 7564 8404 The 'EncryptionProvider' interface is not supported.
10:47:24:145 7564 8404 Getting the dispid of the 'Dispose' method.
10:47:24:147 7564 8404 Success.
10:47:24:147 7564 8404 Getting the dispid of the 'InitializeLoaderService' method.
10:47:24:147 7564 8404 Success.
10:47:24:147 7564 8404 Invoking the 'InitializeLoaderService' method.
10:47:24:147 7564 8404 Success.
10:47:24:147 7564 8404 The instance of the managed add-in class has been created successfully.


And here is the adxregistrator.log content :


Add-in Express Registrator Log File: 01/20/2020 10:22:09

Installation directory: C:Program Files (x86)KnowBe4Phish Alert
Registrator version: 9.4.4644.0
Operating System: Microsoft Windows 10 Professional (build 18362), 64-bit
Process Owner: System
Command Line: "C:Program Files (x86)KnowBe4Phish Alertdxregistrator.exe" /install="PhishAlert.dll" /privileges=admin
Run 'As Administrator': Yes
Process Elevated: Yes
Integrity Level: System
UAC (User Account Control): On
--------------------------------------------------------------
10:22:09 0528 Starting the add-in registration process.
10:22:09 0528 Loading mscoree.dll
10:22:09 0528 Success.
10:22:09 0528 .NET Framework installation directory: 
10:22:09 0528 The latest version of .NET Framework: 'v4.0.30319'
10:22:09 0528 Loading CLR: v4.0.30319.
10:22:09 0528 Calling CLRCreateInstance method.
10:22:09 0528 Success.
10:22:09 0528 Calling GetRuntime method.
10:22:09 0528 Success.
10:22:09 0528 Checking if the hosting API of .NET Framework v4.0 beta is installed.
10:22:09 0528 The hosting API is up to date.
10:22:09 0528 Calling GetInterface method for the CorRuntimeHost interface.
10:22:09 0528 Success.
10:22:09 0528 Starting CLR...
10:22:09 0528 Success.
10:22:09 0528 Getting the CLR version.
10:22:09 0528 The CLR v4.0.30319 has been initialized successfully.
10:22:09 0528 Creating a new domain setup.
10:22:09 0528 Success.
10:22:09 0528 Getting the add-in directory.
10:22:09 0528 Success. The directory is 'C:Program Files (x86)KnowBe4Phish Alert'
10:22:09 0528 The 'shadow copy' is disabled.
10:22:09 0528 Creating a new application domain.
10:22:09 0528 Success.
10:22:09 0528 Getting the base directory for the domain.
10:22:09 0528 Success. The directory is 'C:Program Files (x86)KnowBe4Phish Alert'.
10:22:09 0528 Searching for the Add-in Express core library.
10:22:09 0528 Success. The 'AddinExpress.MSO.2005.dll' file is found.
10:22:09 0528 Creating an instance of the 'AddinExpress.Deployment.ADXRegistrator' class.
10:22:09 0528 Assembly identity is 'AddinExpress.MSO.2005'.
10:22:10 0528 Success.
10:22:10 0528 Unwrapping the instance of the 'AddinExpress.Deployment.ADXRegistrator' class.
10:22:10 0528 Success.
10:22:10 0528 Calling the managed registration procedure (DISPID = 1610743823).
10:22:10 1052 32 bits. The 'HKLMSoftwareMicrosoftOfficeOutlookAddInsKnowBe4ReportPhishing.AddinModule' registry key was created successfully for the 'KnowBe4ReportPhishing.AddinModule' class: LoadBehavior=3
10:22:10 1052 32 bits. The 'HKCRCLSID{c6706a1b-6bba-4e58-a82d-c443f328d9c7}InprocServer32' registry key was created successfully for the 'KnowBe4ReportPhishing.AddinModule' class: C:Program Files (x86)KnowBe4Phish Alertdxloader.dll
10:22:10 1052 64 bits. The 'HKLMSoftwareMicrosoftOfficeOutlookAddInsKnowBe4ReportPhishing.AddinModule' registry key was created successfully for the 'KnowBe4ReportPhishing.AddinModule' class: LoadBehavior=3
10:22:10 1052 64 bits. The 'HKCRCLSID{c6706a1b-6bba-4e58-a82d-c443f328d9c7}InprocServer32' registry key was created successfully for the 'KnowBe4ReportPhishing.AddinModule' class: C:Program Files (x86)KnowBe4Phish Alertdxloader64.dll
10:22:10 0528 Registration success.
10:22:10 0528 The add-in registration process is completed with HRESULT = 0.



Do you see anything wrong with the above data? Moreover, is it possible that AddinInitialize() is never called at all?

Thanks.
Posted 21 Jan, 2020 04:35:27 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
The logs look correct.

AppDev writes:
I have seen outlook list our addin correctly with the right location too.


Sorry, what does that mean? List your add-in? What list? What location?

AppDev writes:
Moreover, the addins constructor was executed and finished successfully.


The adxloader.log confirms that the module instance was created correctly. Also, this means the add-in isn't disabled. If it is listed under Active Application Add-ins (see File | Options | Add-ins) then it is loaded correctly. If AddinInitialize doesn't occur in this case, check if the corresponding method is connected to the event.

BTW, how do you know that AddinInitialize isn't called?

Also, check if OnRibbonBeforeCreate occurs in this case.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jan, 2020 04:54:56 Top
AppDev




Posts: 26
Joined: 2016-06-22

1, Sorry, what does that mean? List your add-in? What list? What location?


What I mean is in the outlook->File->Options->AddIns I see the addin listed and enabled. Like this :

User added an image


2. Also, check if OnRibbonBeforeCreate occurs in this case.


I cannot reproduce the issue on my machine but I will try to add a handler for this one during my next debug session with the client.

3. In terms of code, our constructor runs the following sequence :

try {
	Logger.Instance.Info("Constructor Started.");
	InitializeComponent();
	this.AddinInitialize += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinInitialize);
	this.OnError += new AddinExpress.MSO.ADXError_EventHandler(this.OlToysConnect_OnError);
	this.OnRibbonBeforeLoad += new AddinExpress.MSO.ADXRibbonBeforeLoad_EventHandler(this.AddinModule_OnRibbonBeforeLoad);
	Logger.Instance.Info("Constructor Finished.");
} catch (Exception ex) {
    ....
}


Or is it possible that outlook was already executing AddinInitialize() while we were applying the hook? Our catch sequence has logging for crashes too. But i have not seen any logs related to our addin crashing.

I hope this makes sense. Thank you.
Posted 21 Jan, 2020 05:15:41 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
AppDev writes:
I will try to add a handler for this one during my next debug session with the client.


Ignore this since your code handles BeforeRibbonLoad: does it work in your case?

Do you have Office from Microsoft Store? Compare the screenshot at https://www.add-in-express.com/creating-addins-blog/2019/02/27/office-from-store-issues/ with what you have.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jan, 2020 06:04:13 Top
AppDev




Posts: 26
Joined: 2016-06-22
Interestingly, the machine where our problem occurred is click-to-run. And I don't know if that is included in that subset affected by the bug discussed. But i will keep an open eye for that when other issues come in. For now i think the registry data on our addin is working as designed.

My last few questions though are :

Our addin is not working properly because the piece of code critical to initialization did not run because AddinInitialize() hook was not triggered/invoked.

1. Is it possible that the AddinInitialize() hook is never called/triggered?
- Is it possible that this is because the event behind addininitialize never happened?
- Or is it possible that this is because the event behind addininitialize already occurred even before we got the chance to hook into it?
- Or that the addininitize failed to successfully "register-to-listen" on the event it was supposed to monitor?
- What could possibly cause for our handler for AddinInitialize() to never be called?
- In your experience has this happened before?


2. Would you suggest our initialization code to be moved to OnRibbonBeforeCreate() instead?
- It seems OnRibbonBeforeCreate() and OnRibbonBeforeLoad() are called first before AddinInitialize().
- This makes sense in a way as ours is a ribbon addin.

What do you think? Thank you again.
Posted 21 Jan, 2020 07:22:19 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
It should work. If only I remember correctly, it is possible to get an Outlook add-in not loaded if you use Send To | Mail Recipient in the file context menu (in File Explorer).

Please describe the scenario in which you see the issue.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jan, 2020 07:54:36 Top
AppDev




Posts: 26
Joined: 2016-06-22
Well there is nothing really special about it. We just install the addin and then open outlook. Our button shows but it is not initialized properly causing it to not do anything when it gets clicked. But I see the constructor of the addin being executed, but the handler for addininitialize() is never called, making the addin uninitialized and unconfigured. Whenever you click the button, the "onclick()" handler is called, as the logs show it. But since the addin is uninitialized and unconfigured, the "onclick()" handler does not run correctly.

Is it possible that with the latest outlook versions and .net versions, that there are certain conditions where the event behind addininitialize() never get triggered? I remember this problem started happening to some of our clients starting april of 2019. But now there are quite a number of them having this issue. And i cannot reproduce the same issue in all of my test machines.

Thank you again.
Posted 21 Jan, 2020 08:06:58 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
AppDev writes:
We just install the addin and then open outlook.


Before you install your add-in, start Outlook and make sure you don't have an older version(s) of your add-in installed. Did you ever change your add-in from per-user to per-machine?

AppDev writes:
this.AddinInitialize += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinInitialize);


Is it possible that you disconnect that event handler somewhere in your code?

AppDev writes:
Would you suggest our initialization code to be moved to OnRibbonBeforeCreate() instead?


I wouldn't. AddinInitialize should work. If it doesn't, OnRibbonBeforeCreate may behave in the same way this day or other.

Also.

Before you start Outlook after your add-in gets installed, make sure that OUTLOOK.EXE is not running in processes.

Try to turn *all* other COM add-ins off and restart Outlook.

Also send me a screenshot showing the Outlook version information to the support email address; find it in {Add-in Express installation folder}\readme.txt. Make sure your email contains a link tot his topic.

Does a newly created simple add-in demonstrate the same behavior?


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jan, 2020 08:34:21 Top