I�m developing an addin for Excel.  The addin creates a toolbar button in
Excel and when the button is clicked a form is loaded.  The form
references some private assemblies that are in the same folder as the
addin�s .dll file.  When the addin is loaded in Excel, the default
AppDomain�s BaseDirectory is the same directory as the Excel.exe file.
So, when the CLR looks for the private assemblies that the form needs, it
looks in the excel.exe folder and not the addin�s .dll file folder.  Does
anybody have any ideas on how to solve this?  I feel like there is some
simple solution to this and I�m just too dumb to find it.
I�ve tried creating a second appdomain (that has the correct base
directory) and loading the addin�s assembly into it.  But when I create
the form (using appdomain.CreateInstanceAndUnwrap), I can�t cast the
object to a form.  It returns an invalid cast exception.  The exact same
create appdomain code works just fine if it is run in a normal windows
application, but causes the error if it is run in the Excel process.
I also don�t want to install the references assemblies in the GAC.  The
code I'm using looks something like:
string s =Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
AppDomain ad2 = AppDomain.CreateDomain("TestDomain",null,s,s,false);
ObjectHandle oh = ad2.CreateInstance("AssemblyName","TypeName")
Type ojb = (Type) oh.Unwrap();  //the Type inherits MarshalByRefObject

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to