all groups > dotnet interop > july 2007 >
You're in the

dotnet interop

group:

Advice on dynamically loading .Net assembly when cscript.exe is the hosting process



Advice on dynamically loading .Net assembly when cscript.exe is the hosting process Anthony LaMark
7/30/2007 7:14:23 PM
dotnet interop: Hi All,

I have a .Net Assembly that is COM enabled (COM-Interop) and so is
instantiated and used in vbscript and jscript. I install it into the GAC
(during our installation program). This assembly has dependencies on other
..net assemblies (from another companion product) to run. These dependency
assemblies are not put into the GAC though. When I compile my assembly, I
have the companion product assemblies defined as references within the
Visual Studio project. I can find where the dependency assemblies are on
the hard drive by going to the registry though so I can determine their
location. My current problem is that at run-time I cannot use app.config
file to do load the dependent .net assemblies (because the host process is
cscript.exe which is in Windows\system32), rather I am hoping to be able to
have a hook in my .Net Assembly to be able to load the dependency
assemblies. I have read over Assembly.Load and so it looks do-able but I
think I need to not link the dependencies into the dll (i.e. static link)
since I can see that when the system loads my assembly, it is trying to
resolve the dependency assemblies as well. I see this with fuslogvw.exe.
Any advice would be greatly appreciated!

Re: Advice on dynamically loading .Net assembly when cscript.exe is the hosting process Mattias Sjögren
7/31/2007 12:00:00 AM

[quoted text, click to view]

The dependencies shouldn't be loaded until they are actually needed.
If you can hook up a handler to the AppDomain.AssemblyResolve event
before using anything from the dependency assemblies you should be
able to handle it from there.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button