views:

10

answers:

0

The short version I've got a Word Addin in VB.net and VSTO that exposes a COM compatible object via Word.COMAddins.Object, so that the addin functionality can be called External to Word, without accesses to Word itself being cross-process.

The technique worked in VB6, but with VB.net, it still works, but it's much slower than the same code running directly from the addin via a task pane, as if the calls are all cross process when they shouldn't be. x

The Long version This addin essentially does tons of processing on Word Documents. The addin can be run in two ways.

  1. from within Word, using a taskpane
  2. externally, via a set of classes exposed to COM (because I have to provide access to the functionality to VB6 client apps.

BUT, here's the rub. Anyone who's ever done Word automation knows that code that runs perfectly acceptably INPROC with Word (in this case the instance of the ADDIN that Word itself loads), will generally run unacceptably slowly out of process (or cross process).

This app is no different.

Ages ago, I made use of a handy trick to circumvent this issue.

  1. Create a Word Addin as usual
  2. Expose an object via the Word.COMAddin.Object property that will let external code access your addin.
  3. In your external project, instead of manipulating Word directly, Use the Application.COMAddins collection, find your addin, retrieve the exposed COMAddin.Object property from it and then call a method on that object that does the work.

Of course, the call to your COMAddin.Object object will still be cross process, BUT, once execution is in the addin that is IN PROCESS with Word, your addin can now perform all the Word object manipulations it wants and it's fast because they're all in-process calls at that point.

That worked in the VB6 COM days.

But, I put together this VB.net vsto addin, and expose my addin object via the RequestComAddInAutomationService function of VSTO's Connect object

I can make calls into my addin externally and they all work exactly as I would expect them to, except they're all +slow+, very much like the calls into Word are still being performed cross process even though the code making those calls to Word is part of the addin dll that was loaded in-process by Word!

And slow as in a factor of about 10 to 1; what takes 3 seconds to run when run directly from the ADDIN via the task pane, takes ~30seconds to run when called from external code through the COMADDIN.object object.

I'm guessing that I'm running into some sort of issue with .net APPDOMAINS or something and what +really+ constitutes cross proc calls in .net, but I've found nothing so far that would even hint about this sort of thing.

My next step, barring some mystical insight, will be to code up a repro, which could get tricky because of the shear number of elements in play.

Any thoughts?