代码之家  ›  专栏  ›  技术社区  ›  Vilx-

.NET何时检查程序集依赖项?

  •  4
  • Vilx-  · 技术社区  · 15 年前

    同时追求 a spearate problem 我遇到了一个非常特殊的情况。演示代码为:

    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");
        }
    }
    

    我在日志中得到的是:

    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
    

    这对我来说毫无意义。考虑:

    • vjslib 由我的主项目(程序集)引用,其中包括 Global 类。如果无法解析程序集的依赖项,为什么要加载该程序集?
    • SomeClass 在另一个程序集中,该程序集也引用 VJSLB . 某个班级 是否使用 VJSLB 一些成员确实公开了从中的类派生的类 VJSLB ,但此处使用的属性只是一个普通的旧字符串。
    • 为什么堆栈跟踪的第一行没有行号?

    依赖项是否按方法解决?我以为 Microsoft doesn't do such things anymore . 这是怎么回事?

    1 回复  |  直到 15 年前
        1
  •  4
  •   Community Mohan Dere    9 年前

    我相信当clr遇到对il中某个类型的引用时,它会尝试加载它。它们可能导致加载组件。因此,所有依赖程序集不一定在启动时加载-它们将按需加载。

    编辑:查看此问题 SO 关于何时加载程序集。书“clr via c”还讨论了在IL中的jit遇到类型输入时加载程序集的问题。

    推荐文章