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

标签 .net assemblies dependencies

在追求的同时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类(class)。如果无法解析其依赖项,为什么要加载该程序集?
  • SomeClass位于另一个程序集中,该程序集也引用了 vjslib . SomeClass确实使用 vjslib并且某些成员确实公开了从 vjslib 中的类派生的类,但这里使用的属性只是一个普通的旧字符串。
  • 为什么堆栈跟踪的第一行没有行号?

  • 依赖项是否在每个方法的基础上解决?我以为Microsoft doesn't do such things anymore .这里发生了什么?

    最佳答案

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

    编辑:在 SO 上看到这个问题关于程序集何时加载。 “CLR via C#”一书还谈到了在 IL 中的 JIT 遇到输入时程序集被加载。

    关于.net - .net 何时检查程序集依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3707835/

    相关文章:

    c# - C++/CLI 中 C# 类的显式类型转换

    c# - csproj 根据操作系统复制文件

    android-studio - 从所有配置中排除多个传递依赖项

    python - 动态依赖项在 python setup.py 中如何工作?

    c# - CS0102 类型 'A' 已包含 'set_color' 的定义

    c# - 找不到路径的一部分 C#

    c# - 预加载所有程序集 (JIT)

    c# - 我如何订阅在另一个程序集中引发的事件

    c# - 当我在程序启动后复制 DLL 时,运行时加载程序集失败

    gradle - 无法解决 ':app@debugUnitTest/compileClasspath'、:app@debugAndroidTest/compileClasspath 的依赖关系