Home All Groups Group Topic Archive Search About

Help with registering AssemblyResolve event

Author
26 Jul 2006 8:19 PM
lithel
I am writing an application that uses a set of library assembly dlls
that are located in a command line passed location.  Originally, I
tried to solve this problem by creating an AssemblyResolve handler and
registering it very early in hte main function.

The problem is that the application actually uses some of these
assemblies.  In particular, one of the classes (named MainWindow)
derives from a class in the library.  If the runtime attempts to create
a MainWindow before the handler is loaded, then I have a problem.

Fair enough.  However, the way I understand the JIT, I thought it would
not attempt to load dependent libraries until the class is used or a
static call is made on that class.  I made a seperate "Launcher" class
that the main funciton and the handler, but I am still failing to
resolve the assembly before I even reach my main function.

I am reasonably certain that if I wrote an entire launcher assembly
then this method would work, but I'm hoping there's a "cleaner" way to
fix this problem.  Has anyone ever run into this problem?

Author
26 Jul 2006 9:27 PM
lithel
Alright, I actually figured this out, and it was a silly mistake on my
part.  In the main function I had:

Application.Run(new MainWindow())

which uses the main window!  That's why the JIT was trying to load the
external assembly (since MainWindow inherits from a class in there).
Fixed it by writing another method called "StartApp" that includes that
one line and then calling that function where I used to have the
Application.Run line.


lit***@gmail.com wrote:
Show quote
> I am writing an application that uses a set of library assembly dlls
> that are located in a command line passed location.  Originally, I
> tried to solve this problem by creating an AssemblyResolve handler and
> registering it very early in hte main function.
>
> The problem is that the application actually uses some of these
> assemblies.  In particular, one of the classes (named MainWindow)
> derives from a class in the library.  If the runtime attempts to create
> a MainWindow before the handler is loaded, then I have a problem.
>
> Fair enough.  However, the way I understand the JIT, I thought it would
> not attempt to load dependent libraries until the class is used or a
> static call is made on that class.  I made a seperate "Launcher" class
> that the main funciton and the handler, but I am still failing to
> resolve the assembly before I even reach my main function.
>
> I am reasonably certain that if I wrote an entire launcher assembly
> then this method would work, but I'm hoping there's a "cleaner" way to
> fix this problem.  Has anyone ever run into this problem?

AddThis Social Bookmark Button