SmartTag -> IPC Channel -> VSTO Addin

N

NickP

Hi there,

I am using some IPC communication classes that I created a while back
and have never experienced any issues with them whatsoever.

This is how I am currently using it,

1. When my Add-In loads and the Startup event is raised I start the IPC
server. As this only happens once during the entire lifetime of Word.
2. When the SmartTag verb is called I communicate the verb with the
server.
3. The server recieves the messages.

Unfortunately this is where things start going a little odd. At
current, any object that I try accessing, causes the Add-In and Word to just
freeze, with no error messages. I originally thought that this could be due
to a cross threading operation. So in order to resolve this I have done the
following,

1. When my Add-In loads and I create the IPC server, I also create a
CustomTasksPane. The Add-In supports multiple custom task panes, but I grab
a reference to the first instance in order to use it for Invocation back to
the thread that the Add-In is running on.
2. When the server recieves the messages, I tell the CustomTasksPane to
invoke a method that handles the messages.

Unfortunately the second I access the CustomTasksPane, the Add-In and
Word, just freeze, in exactly the same way as before. I have tried checking
to see if the CustomTasksPane object is Nothing, but it is not. I have also
tried wrapping the call within a Try Catch block, this has no effect either.

I am not quite sure what could be causing this, as I said previously, it
works great in any other .NET application I have used it in, and that has
been quite a few. Anyways, I'll keep plugging at it as usual, but if anyone
has any helpful suggestions that would be fantastic!

Nick.
 
N

NickP

Hey there,

Well that was quickly solved! I managed to resolve the problem by
invoking via the parent form of my custom task pane control, rather than the
control itself.

I'm not quite sure why invoking from the control doesn't work though
mind you :-\

Nick.
 
N

NickP

I take that back, it didn't work, it just fell through with an exception, as
opposed to freezing. The parentform of the CustomTaskPane control is
Nothing.

Nick.
 
N

NickP

Hi again,

Right, I have managed to narrow the problem down a little, but it seems
a little odd to me.

The VSTO code is all running in the same app domain, yet the SmartTag
component isn't. This is fine because I have the IPC communication channel
between the 2 which appears to work fine.

When my VSTO add-in launches, and I add a CustomTaskPane to a window, I
add it to a dictionary of Windows, associated with CustomTaskPanes. What I
find really odd is the same line of code, has different results...

-----

Private cLisTaskPanes As Generic.Dictionary(Of
Microsoft.Office.Interop.Word.Window, Microsoft.Office.Tools.CustomTaskPane)

cLisTaskPanes.Item(Application.ActiveWindow)

* the above line returns the correct object when being called from the VSTO
side. yet returns Nothing when being called via the IPC channel callback.
Even though it insists that the list contains 2 items, it just does not
match the ActiveWindow reference to any of the keys.

-----

One would presume that no matter where I am calling ActiveWindow from,
as long as it is actually being called in the same window, I should get the
same return value right? Even if I call it via 2 completely different
applications that aren't communicating with each other.

Any ideas on this would be great! Not that I'm holding my breath.

Nick.
 
N

NickP

Something is definitely amiss. I have just discovered that the Hash code of
the Word Application object keeps changing when checked through the IPC
callback.

The SmartTag runs in app domain ID 1, and the VSTO code in app domain 2.
Although I am informed that that the callback successfully enters into app
domain 2, the hash code of the application object is different, and as it
varies each time, this would explain why accessing it causes it to crash.

Any ideas why this object is even changing in the first place?

Nick.
 
N

NickP

More to the point, all reference objects are invalid after the callback.
Only value objects hold their true value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top