AppDomain.baseDirectory is different through COM vs directly

G

Guest

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.
 
G

Guest

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.
 

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