Problem with custom thread identity when calling ShowDialog

  • Thread starter Eiríkur Fannar Torfason
  • Start date
E

Eiríkur Fannar Torfason

Hi everybody,

I'd like to tap into your collective brainpower. I have a problem with a
managed Office Add-in and, as much as I hate to admit it, I need some help.

My add-in is written in Visual Studio 2005 and therefore uses .NET Framework
2.0. It's a shared add-in that we use with Outlook, Word, Excel and
Powerpoint. I used the shim wizard to create a shim for the add-in and for
the most part, everything is honky dory.

The add-in uses a factory to load at run-time a gateway to communicate to a
server application. We have different gateways for different types of server
applications. One of the gateways puts a custom identity on the thread once
the user has been authenticated (this custom identity class inherits from the
GenericIdentity class). The custom identity class is marked as serializable.

The problem is when my add-in displays a dialog by calling the ShowDialog
method of a form. It seems that this causes the current thread to switch to
another appdomain. When the run-time then tries to marshal (by value) the
custom identity class, I get a serializationexception (could not load type
'<custom identity class>'...). Now, to solve this locally on my development
machine, all I had to do was to install the assembly that contains the custom
identity class into the GAC. I tested this in Office 2007 and everything
worked like a charm. I then proceeded to modify the installer for the product
that contains the add-in to install the same assembly into the GAC on target
machines. I then tested it on a virtual pc with Office XP but much to my
dismay, any office application using the add-in would crash on startup. I
tested it also on a different virtual pc machine with office 2003 and still I
got the same behaviour. Just to make sure, I reverted my changes in the
installer project so that the assembly was not installed in the GAC and tried
again and lo and behold, no crashes.

I'm therefore in a pickle. There are three possible solutions that I'd like
to explore.
1. Is there a way to show a dialog without causing the thread to travel to a
different appdomain?
2. Can I modify the shim to somehow load the assembly containing the custom
add in type, either as a shared assembly for all appdomains or at the very
least into the default appdomain. I'm not proficient in C++ so this would be
somewhat of a challenge.
3. Can I modify the custom identity somehow so that the other appdomain
doesn't have to be able to load the assembly that contains it's type. Would
inheriting from MarshalByRef make any sense?

Any and all help would be much appreciated.

BTW my installer uses a bootstrapper that installs the shared add-in update.
 
E

Eiríkur Fannar Torfason

I did some further testing and discovered something rather odd. I ran the
installer on a virtual pc. This version of the installer did not attempt to
place the assembly with the custom identity class into the gac. Instead I did
so manually using gacutil.exe after running the installer. In this case,
everything works fine. It seems that office only crashes if the msi package
places the assembly in the gac. Then the question becomes, how is the windows
installer way of placing an assembly in the gac different from the way
gacutil does it?
I'd prefer if the MSI package installed it natively. Bundling gacutil.exe in
the setup and calling it as a custom action does not appeal to me (calling
executables as custom actions in an MSI package does not work without a
bootstrapper in Windows Vista for example).
 

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