I am calling a third-party library in two separate programs. One program works and the other does not. The problem is that .NET is attempting to resolve assembly references at different times.
Here are the details. The third-party library has a class initializer that registers a handler for the ResolveAssembly event in the appdomain. If this handler is not registered, a call to the constructor for the class will fail.
In the program that works, this event is raised just before the constructor is called (i.e., in the debugger, I see the event get raised as I step into the constructor). In the program that does not work, the event is raised just prior to the method which contains the call to the constructor (i.e., I see the event get raised as I step into the calling method). In the former case, the event is registered by the class initializer before the event is raised; in the latter, the resolution happens before the class initializer is called, and I later get a "file not found" exception in the constructor.
As the two methods are identical, I have to assume that there is something about the containing program that is causing the different behavior. But I have not been able to identify any compiler options or appdomain settings that might be causing it. Are there any subtle assembly resolution rules that I might be missing?
EDIT: To be clear, I'm asking for a link to information about exactly when the CLR attempts to resolve references, as opposed to how. In both cases, I am calling a method that looks like this:
void CreateObject()
{
SomeObject o = new SomeObject();
}
In one case, the resolution happens as I step into CreateObject. In the other, it happens just prior to the SomeObject constructor. There has to be a reason why the CLR is able to delay assembly resolution in the second case, but I haven't been able to find it.