什么时候.NET检查装配的依赖? [英] When does .net check for assembly dependencies?

查看:130
本文介绍了什么时候.NET检查装配的依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在追求 我已经走过了spearate问题一个非常特殊的情况。一个演示code将是:

While pursuing a spearate problem I've come to a very peculiar situation. A demo code would be:

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 log is:

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

这是没有意义的无论什么。试想一下:

This makes no sense to me whatsoever. Consider:

  • vjslib 是我的主要项目(组装)引用其中包括全球类。为什么装配装在所有如果它的依赖不能得到解决?
  • SomeClass的是在另一个组件,它也引用 vjslib SomeClass的并使用 vjslib 一些成员也暴露出从班 vjslib <派生类/ code>,但这里使用的属性只是一个普通的老字符串。
  • 为什么会出现在堆栈跟踪的第一行没有行号?
  • vjslib is referenced by my main project (assembly) which includes the Global class. Why was the assembly loaded at all if its dependencies could not be resolved?
  • SomeClass is in another assembly which also references vjslib. SomeClass does use vjslib and some members do expose classes that are derived from classes in vjslib, but the property used here is just a plain old string.
  • Why is there no line number in the first line of the stack trace?

是依赖解析在每个方法的基础?我认为微软不会做这样的事情了。这是怎么回事吗?

Are the dependencies resolved on a per-method basis? I thought that Microsoft doesn't do such things anymore. What's going on here?

推荐答案

我相信,当遇到CLR参考某种类型的白细胞介素,它会尝试加载它。而它们可能会导致加载程序集。因此,所有相关的组件并不一定获得在启动时加载的 - 他们将会得到按需加载

I believe that when CLR encounter reference to some type in IL, it attempts to load it. And they may result in loading the assembly. So all dependent assemblies does not necessarily get loaded at the start up - they will be getting loaded on demand.

编辑:请参阅<一个这个问题href="http://stackoverflow.com/questions/1945057/when-does-the-clr-try-to-load-a-referenced-assembly">SO关于装配时被加载。该书通过C#CLR还谈到组装得到加载时类型由JIT中IL遇到。

See this question on SO about when assembly gets loaded. The book "CLR via C#" also talks about assembly getting loaded when type in encountered by JIT in IL.

这篇关于什么时候.NET检查装配的依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆