CurrentTaskPaneInstance is null

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

CurrentTaskPaneInstance is null
adxWordTaskPanesCollection.CurrentTaskPaneInstance is returning null  
Subscribe
Premkumar Elangovan




Posts: 19
Joined: 2018-12-28
Lately some of our customers are complaining that suddenly our Addin is throwing an error. This error is supposed to be thrown when the taskpane instance is null. We are trying understand why suddenly out of the blue this is happening. What is causing Add-in Express to return a null instance. We haven't made any changes to the code for the past 6 months. Is it something to with Windows or Office update?


ResultsWordTaskPaneNew taskPane = (ResultsWordTaskPaneNew)this.adxWordTaskPanesCollectionResults.CurrentTaskPaneInstance;
if (taskPane == null)
 {
    MessageBox.Show("Please close and reopen Word to use REF-N-WRITE AddIn", "Restart Word!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
    return;
 }


User added an image
Posted 06 May, 2024 09:16:44 Top
Andrei Smolin


Add-in Express team


Posts: 18987
Joined: 2006-05-11
Hello Premkumar,

Typically, this occurs if the add-in code getting an instance of the pane relies on an event of the object model. This approach poses a problem as the Add-in Express panes are built around the windowing of the host application, not around events of the host application's object model. Say, a pane instance may still not be created at the moment when Word generates the DocumentOpen event; instead, Add-in Express creates it when Word creates a window to show the document being opened. Whether the DocumentOpen event occurs before or after the window is created depends on the implementation of Word. And your case might be caused by Microsoft updating the implementation.

The list of Word events where the pane instance is created using the logic above includes AddinStartupComplete, WindowActivate, WindowDeactivate, NewDocument, DocumentOpen, DocumentChange, DocumentBeforeClose.

We recommend that you update the add-in code so that the pane itself is the source of the event triggering your functionality. Say, you can use the ADXBeforeTaskPaneShow event of the task pane class to be notified about the specified pane instance going to show; in this event, you can prevent the pane from showing by setting thePane.Visible = false. When the pane becomes hidden, you'll get the ADXAfterTaskPaneHide event of the task pane class.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 06 May, 2024 16:40:29 Top
Premkumar Elangovan




Posts: 19
Joined: 2018-12-28
Thanks Andrei. All the events are triggered in response to user clicking the buttons in the Ribbon button panel. We spoke to the customer to get further details as to when this is happening. It happens when user clicks directly on the file to open it on Word. If he fires MS Word first and then opens the document from within Word, the problem dissapears. We thought if user can see the Ribbon buttons, then the window has been sucessfully created and taskpane instances will be valid. I am bit confused as to how to make pane source of the event?

 
 //This is the call back function for search button.
 private void searchButton_OnClick(object sender, IRibbonControl control, bool pressed)
 {
       
    string selectText = string.Empty;

   //Get the selection
   selectText = this.WordApp.Selection.Text;
 
          
   //Get the taskpane corresponding to the active document
   ResultsWordTaskPaneNew taskPane = ResultsWordTaskPaneNew)this.adxWordTaskPanesCollectionResults.CurrentTaskPaneInstance;
   if (taskPane == null)
   {
       MessageBox.Show("Please close and reopen Word to use REF-N-WRITE AddIn", "Restart Word!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
       return;
   }

    taskPane.wordApp = (Microsoft.Office.Interop.Word.Application)this.WordApp;

    //Hide the taskpane just in case
    taskPane.RegionState = AddinExpress.WD.ADXRegionState.Hidden;
    taskPane.Hide();

    //Business logic(update panel contents)
     taskPane.SearchCode(selectText);
     
     //Make the taskpane visible
     AddinExpress.WD.ADXRegionState.Normal;
     taskPane.Show();

    }
Posted 15 May, 2024 08:34:10 Top
Andrei Smolin


Add-in Express team


Posts: 18987
Joined: 2006-05-11
Hello Premkumar,

Could you please create a test add-in with two Ribbon buttons? One button should hide the pane, perform the SearchCode call and show a message box signalling that the method is complete. The second button shows the pane. If this approach works, you should split your code in two parts. When the first part completes (= when the SearchCode() call completes), it uses the machinery we describe in section Wait a little; see the PDF file in the folder {Add-in Express}\Docs on your development PC. When the hidden window described in that section receives the message sent by the first part, it raises an event that you handle to perform the second part - namely, show the pane. A small delay between these calls should help.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 16 May, 2024 18:20:11 Top
Premkumar Elangovan




Posts: 19
Joined: 2018-12-28
Dear Andrei,
Finally, we managed to figure out which customers are facing this issue of taskpane not being created. Customers who signed up for the ‘Microsoft 365 Insider Program’ were facing this issue. Once we got them to opt out of the Insider Program and roll the version back to the normal channel, the taskpanes appeared and the Addin started working fine.

My understanding is that people who are part of ‘Microsoft 365 Insider Program’ get to test a future release of Microsoft Word. It appears that there are issues with taskpanes being shown properly in the future version. Is it something to be concerned about? At some point this version will be rolled out to the public, isn’t it?

Regards,
Prem
Posted 13 Jun, 2024 17:36:25 Top
Andrei Smolin


Add-in Express team


Posts: 18987
Joined: 2006-05-11
Hello Prem,

This issues shows why Add-in Express doesn't support Office versions obtained through the the Beta channel.

Premkumar Elangovan writes:
At some point this version will be rolled out to the public, isn’t it?


I strongly believe it won't be *this* version.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Jun, 2024 15:22:53 Top
Premkumar Elangovan




Posts: 19
Joined: 2018-12-28
Thanks Andrei.
Posted 14 Jun, 2024 15:31:03 Top
Andrei Smolin


Add-in Express team


Posts: 18987
Joined: 2006-05-11
Hello Prem,

Turns out I'm wrong and they provided that version through the Current channel. I've sent you an email with a download link to the assembly providing a fix and instruction on installing the assembly. Please check your Inbox and Junk Email.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Jun, 2024 07:43:07 Top
Premkumar Elangovan




Posts: 19
Joined: 2018-12-28
Thanks Andrei. I have updated the assemblies and released a new version to the customers.
Posted 27 Jun, 2024 10:20:02 Top