Get DTO back from ComAddin

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

Get DTO back from ComAddin
 
gjvdkamp




Posts: 39
Joined: 2018-08-28
Hi,

I have an Excel addin, on which I want to run things in the background.

So I open up an second eXcel in the background and get the addin. On that I can call methods, but only when they're simple types.

I get the addin like this:

var _backgroundXL = new Microsoft.Office.Interop.Excel.Application();
var addin = _backgroundXL.COMAddIns.Item("MyAddIn").Object; // addin is type dynamic 



I have two test methods on my C# addin:
public List<int> GetIntList(); // this one returns indeed a list<int> to the master addin 
public List<SomeType> GetTypedList(); // this one returns null 


I call like this:
var res = addin.GetIntList(); // indeed a list of int 
var res2 = addin.GetTypedList(); // I keep getting null .. 


This also retured null:
object value = addin.GetType().InvokeMember("GetTypedList", BindingFlags.InvokeMethod, null, addin, null);


Do you know how to get the background addin to return more complicated classes?

I also tried
public List<ISomeType> GetTypedList2(); // but that also retuns null 
Posted 05 Aug, 2020 08:18:25 Top
Andrei Smolin


Add-in Express team


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

gjvdkamp writes:
I have an Excel addin, on which I want to run things in the background.
So I open up an second eXcel in the background and get the addin.


For me these sound non-connected. To do some stuff in the background, you create a thread and process that stuff on that thread. Starting a new Excel seems to be an over-reaction. First, starting a new Excel creates a new instance of your add-in. The new instance lives in a different AppDomain and you can only communicate with it using simple types; say, you can serialize that array or list, whatever. Also, there's a restriction: no books having the same name can be opened in Excel, even if you have several Excel instances.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Aug, 2020 09:33:09 Top
gjvdkamp




Posts: 39
Joined: 2018-08-28
Hi Andrei, passing strings worked indeed, thx!

I hear what you're saying but I have a few other design goals that make we want to it like this.
Posted 06 Aug, 2020 02:12:04 Top
Andrei Smolin


Add-in Express team


Posts: 17324
Joined: 2006-05-11
Welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Aug, 2020 03:44:11 Top