Home All Groups Group Topic Archive Search About

AppDomain.baseDirectory is different through COM vs directly

Author
8 Mar 2007 7:13 PM
Andrew Stoneham
I have a dotnet application that can be loaded directly as a executable
(loading a winForm) or as a COM object through one of our legacy
applications.  This application also loads components at runtime from
Assembly.GetExecutingAssembly.Location + "\components"

The problem is that when the application is loaded through the COM Component
the AppDomain.base directory is divverent from the
Assembly.GetExecutingAssembly.Location and so I get a FileNotFoundException
inside a ReflectionTypeLoadException.  I have traced this down to the fact
that the loaded assembly is looking for a dll that is a) already loaded
(because that's the assembly that's loading the new assembly) and b) is in
the Assembly.GetExecutingAssembly.Location.  And that the
AppDomain.BaseDirectory is different from this location.

My question is, is there any way to change the location that
AppDomain.BaseDirectory is looking at or a way to change the DynamicDirectory
to the location of the base dll.

Author
9 Mar 2007 4:41 PM
Andrew Stoneham
I have solved my problem by using Assembly.loadFrom() instead of
Assembly.loadFile().  What appears to have been happening is that when I
tried to examine the types that the loaded assembly had, it tried to load the
whole assembly from scratch, but because the base directory was different
(due to the app being loaded as a COM object) the referenced assembly
couldn't be found even though it had already been loaded.

Show quote
"Andrew Stoneham" wrote:

> I have a dotnet application that can be loaded directly as a executable
> (loading a winForm) or as a COM object through one of our legacy
> applications.  This application also loads components at runtime from
> Assembly.GetExecutingAssembly.Location + "\components"
>
> The problem is that when the application is loaded through the COM Component
> the AppDomain.base directory is divverent from the
> Assembly.GetExecutingAssembly.Location and so I get a FileNotFoundException
> inside a ReflectionTypeLoadException.  I have traced this down to the fact
> that the loaded assembly is looking for a dll that is a) already loaded
> (because that's the assembly that's loading the new assembly) and b) is in
> the Assembly.GetExecutingAssembly.Location.  And that the
> AppDomain.BaseDirectory is different from this location.
>
> My question is, is there any way to change the location that
> AppDomain.BaseDirectory is looking at or a way to change the DynamicDirectory
> to the location of the base dll.

AddThis Social Bookmark Button