Invalid parent window adding custom task pane - Excel SAP Integration

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

Invalid parent window adding custom task pane - Excel SAP Integration
 
Developer


Guest


Hello,

we have a customer using an Excel running integrated in SAP.
When starting it, he gets the following Exception:

System.ArgumentException: Invalid parent window specified. 
System.RuntimeType.ForwardCallToInvokeMember(memberName As...
   mscorelib.dll: N 0191 (0xBF) IL
at AddinExpress.MSO.ICTPFactory.CreateCTP(CTPAxID As String, ...
   mscorelib.dll: N 00000 (0x0) JIT
at AddinExpress.MSO.ADXAddinModule.AddCustomTaskPanes(parent ...
   mscorelib.dll: N 000 (0x0) IL


I unfortunately can't provide the complete exception information, since I only have a screenshot of the exception message dialog, but it looks very similar to the exception in this topic: https://www.add-in-express.com/forum/read.php?FID=5&TID=11124

We add a task pane on start which we are then using to show documentation when the help ribbon button is pressed. The preview of windows explorer doesn't seem to have any issues.

What are you experiences with your add in running integrated in other applications?
Is the a bug on your side (since it occurs in your assembly) or are integrated environments generally a problem regarding addition of task panes? What would you suggest to do in this case?
Posted 26 Mar, 2019 06:46:15 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Andreas,

Thank you for the detailed description.

I have just created a small Excel add-in with a simplest Custom Task Pane and tested it with the following "integration" scenario:
- Start Microsoft Word.
- On the Insert tab, click Table and choose Excel Spreadsheet.
- Fill some data in the embedded Excel worksheet.
- Close Microsoft Word.

I don't see any exceptions. Could you please test your add-in in the same way?
Posted 26 Mar, 2019 07:28:46 Top
Developer


Guest


Hello Dmitry,

I don't get an exception this way either.

Do you prevent adding a task pane when you recognize you are in an embedded environment or does Word somehow know what to do? When I am inside the Excel in Word, ribbon changes to the one of Excel but when I click on the help ribbon button which normally activates the task pane, nothing happens when inside Word?

So it seems the integration inside of SAP is kind of different than the one in Word, because on the screenshot I have it shows the whole excel including the (minimized) ribbon running inside a SAP window.

Excel in this case is version 2010 by the way.
Posted 27 Mar, 2019 05:20:41 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Andreas,

Do you prevent adding a task pane when you recognize you are in an embedded environment or does Word somehow know what to do?


Yes, it is our code that prevents a custom task pane from being added in this case. As far as I remember, the https://docs.microsoft.com/en-us/office/vba/api/excel.application.usercontrol is used for such purposes.

So it seems the integration inside of SAP is kind of different than the one in Word, because on the screenshot I have it shows the whole excel including the (minimized) ribbon running inside a SAP window.


Do you have an idea of how we can emulate the SAP behavior?

Excel in this case is version 2010 by the way.


I doubt that Excel version matters.
Posted 27 Mar, 2019 05:58:13 Top
Developer


Guest


Dmitry Kostochko writes:
Do you have an idea of how we can emulate the SAP behavior?


Unfortunately not, my hope was you already had some experience dealing with such kind of environment.
Posted 29 Mar, 2019 01:44:39 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Andreas,

As far as I remember, we did not face such environment yet. Could you please try to create a new simple Excel add-in with a single custom task pane, without any code and try to test it in that environment?
Posted 29 Mar, 2019 04:16:52 Top
Developer


Guest


Hello Dmitry,

I have no access to the customers environment at the moment. What do you expect to happen in this test scenario? Unless the error message isn't completely misleading, I'd guess exact the same exception will occur.

But I'm a little confused since the customer tells us he can use the add in after the message window is closed. I first thought the exception has to occur when
this.TaskPanes.Add(this.adxHelpTaskPane);
is called what happen in the initialize method, which is called in our AddinModule's constructor...

So if the AddIn still runs, it seems in this line the pane is only added to your collection and the attempt to attach it to a parent window happens later. Am I right with this suggestion? When does that happen and can I catch this exception myself?

Best regards
Andreas
Posted 05 Apr, 2019 05:17:39 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Andreas,

The call stack in your first post shows that the issue occurs when an instance of your UserControl is being created. The suggestion above was meant to find out whether the issue is caused by the code of Add-in Express or by your code.

I consulted our guys and among other things they pointed out that UserControl.Parent is null in Excel. I can't tell you whether this relates to the issue or not; we dont have SAP and thus we can't reproduce the issue to find out details. I can suggest that you try using ADXExcelTaskPane instead.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2019 04:51:14 Top
Developer


Guest


Hello Andrei,

I know it's hard to find a solution without being able to reproduce the error. If it's not possible to avoid the exception yet, I would like to catch it at least. The exceptions seems not to happen when I'm adding the TaskPane to your list - it seems somehow later you process the TaskPane list and then the exception occurs.

Is there any location to catch this exception? Where is AddCustomTaskPanes called?

Best regards
Andreas
Posted 11 Apr, 2019 02:49:03 Top
Andrei Smolin


Add-in Express team


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

To intercept that exception, you need to handle the OnError event of the add-in module. Alternatively, since getting that exception means the custom task pane is not created, you can prevent the custom task pane from being created: in the OnTaskPaneBeforeCreate event, if ExcelApp.UserControl is true, set e.Cancel=true.

In case you must have that pane shown, switch to using Advanced Excel Task Panes; see section Step #12 ?Â?Ð?ã Creating Advanced Task Panes in Excel 2000-2019, see the PDF file in the folder {Add-in Express}\Docs on your development PC.


Andrei Smolin
Add-in Express Team Leader
Posted 11 Apr, 2019 06:44:48 Top