Help with registering AssemblyResolve event

L

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?
 
L

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.
 

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