Excel calls a .NET automation server from two different AppDomains applications?

I have an Excel plug-in (written in C #) with a static variable that underlies the singleton data cache:

static DataCache _instance;

It is accessed using three different code paths:

  • Event handlers on the VSTO ribbon panel initialize an instance and also read it for display in auxiliary dialogs
  • An RTD server (a class declared by [ComVisible] that implements the IRtdServer interface) uses data for RTD formulas
  • A set of automation calls (implemented in another class declared by [ComVisible]) also works on data. They are invoked using VBA code, which is invoked when you click buttons on an Excel worksheet.

EDIT (# 3):

Depending on the order in which these code paths are started, I find that my code runs in two separate AppDomains.

All access from tape-tape event handlers happens in the AppDomain called MyPlugIn.vsto. If this is the FIRST access to my COM object, then all subsequent calls (including RTD calls) are found in the same AppDomain.

, FIRST- RTD, RTD AppDomain, "DefaultDomain". ( RTD.) DataCache AppDomain MyPlugIn.vsto. , RTD , DataCache ( , AppDomain, ).

, Excel VSTO AppDomain VSTO. , COM- , AppDomain , , , VSTO AppDomain.

, DataCache , , AppDomain RTD- ?

+5
2

, , AppDomains, , , , AppDomains.

, :

VSTO AppDomain. COM- factory ( RTD-) AppDomain, AppDomain. COM- .

, Excel, . RTD .NET COM- AppDomain . , , " " .

:

  • - RTD, .NET. , , RTD Excel Application.RTD RTD.

  • RTD- - Excel AppDomain, , AppDomain, RTD-.

  • Add-In Application.AddIns.... COM- ...

  • ( COM-) RTD-. - , VSTO AppDomain, RTD- AppDomain.

  • , VSTO, AppDomain . , , , , " Microsoft Office Systems" ( , ), AppDomain.

  • : Excel-Dna ( : ). Ribbons, RTD UDF , , AppDomain. , - RTD , VSTO ( ..), .

, .

- Govert -

+1

:

static DataCache _instance = new DataCache();

( ), , _instance . , .

-, ​​,

Lock (_lockObject)
{
...
}

. .

, , , COM-, STA .

!

-2

All Articles