gjvdkamp
Posts: 56
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 |
|
Andrei Smolin
Add-in Express team
Posts: 18817
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.
Andrei Smolin
Add-in Express Team Leader |
|
gjvdkamp
Posts: 56
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. |
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Welcome!
Andrei Smolin
Add-in Express Team Leader |
|