When is .net validation performed for build dependencies?

Pursuing a problem with spearate , I came to a very peculiar situation. Demo code:

public class Global : HttpApplication { protected void Application_Start(object sender, EventArgs e) { Log("In Application_Start"); SomeClass.SomeProp = ConfigurationManager.AppSettings["PropValue"]; } protected void Application_BeginRequest(object sender, EventArgs e) { Log("In Application_BeginRequest"); try { this.Application_Start(null, null); } catch ( Exception ex ) { Log(ex.ToString()); } Log("At the end of Application_BeginRequest"); } } 

What I get in my journal:

 In Application_BeginRequest Could not load file or assembly 'vjslib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. System.IO.FileNotFoundException at MyRootNamespace.Global.Application_Start(Object sender, EventArgs e) at MyRootNamespace.Global.Application_BeginRequest(Object sender, EventArgs e) in D:\My Documents\Visual Studio 2008\Projects\SolutionDir\ProjectDir\Global.asax.cs:line 109 At the end of Application_BeginRequest 

It makes no sense to me at all. Consider:

  • vjslib refers to my main project (assembly), which includes the Global class. Why is the assembly loaded at all if its dependencies cannot be resolved?
  • SomeClass is in another assembly, which also references vjslib . SomeClass uses vjslib , and some members expose classes that are derived from classes in vjslib , but the property used here is just an old string.
  • Why is there no line number in the first line of the stack trace?

Are dependencies allowed based on each method? I thought Microsoft no longer does such things . What's going on here?

+4
source share
1 answer

I believe that when the CLR encounters a reference to some type in IL, it tries to load it. And they can lead to assembly loading. Thus, all dependent assemblies are not necessarily loaded at startup - they will be loaded on demand.

Edit: See this question at fooobar.com/questions/1296858 / ... about downloading the assembly. The book "CLR via C #" also talks about loading an assembly when a type is encountered by JIT in IL.

+3
source

All Articles