不是所有的组件都被加载到AppDomain中bin文件夹中 [英] Not all assemblies are being loaded into AppDomain from the bin folder

查看:103
本文介绍了不是所有的组件都被加载到AppDomain中bin文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的方法应该检索加载本地(在bin文件夹)组件的列表:

I have the following method that should retrieve a list of loaded local (in bin folder) assemblies:

static IEnumerable<Assembly> GetLocalAssemblies()
    {
        Assembly callingAssembly = Assembly.GetCallingAssembly();
        string path = new Uri(Path.GetDirectoryName(callingAssembly.CodeBase)).AbsolutePath;

        var assemblies = AppDomain.CurrentDomain.GetAssemblies();
        return assemblies.Where(x => !x.IsDynamic && new Uri(x.CodeBase).AbsolutePath.Contains(path)).ToList();
    }  



不过,组件的列表丢失,我需要它一对夫妇组件有。我需要的是管理(C#.NET 4)大会,在该项目中引用,并出现在bin文件夹。

But, the list of assemblies is missing a couple assemblies that I need it to have. The assemblies I need are managed (c# .net 4), are referenced in the project, and are present in the bin folder.

为什么二进制文件出现在bin文件夹不扫到的AppDomain应用程序启动时?

Why are binaries that are present in the bin folder NOT swept into the AppDomain when the application starts?

推荐答案

阿迪尔拥有它,但更详细:

Adil has it, but in more detail:

在.NET CLR使用即时编译。除其他事项外,这意味着它加载在第一次使用集。所以,尽管组件被使用的组件引用,如果引用尚未执行程序所需的由CLR,他们没有加载,所以不会出现在当前的AppDomain组件的列表。

The .NET CLR uses Just-In-Time compilation. Among other things, this means it loads assemblies on first use. So, despite assemblies being referenced by an assembly in use, if the references haven't yet been needed by the CLR to execute the program, they're not loaded and so will not appear in the list of assemblies in the current AppDomain.

这可能会或可能不适用的另一件事是,如果你有在GAC的程序集的版本相同,则CLR使用GAC优先在地方议会中,除非路径这些程序集在DEVPATH环境变量中指定。如果是这种情况下和CLR使用任何的失踪集的GAC复制,他们将有不同的基本代码值,并在您的LINQ查询结果将显示不出来。

Another thing which may or may not apply, is that if you have the same version of the assembly in the GAC, the CLR uses the GAC preferentially over local assemblies, UNLESS the path to those assemblies is specified in the DEVPATH environment variable. If this is the case and the CLR is using the GAC copy of any of the "missing" assemblies, they'll have differing CodeBase values and won't show up in your Linq query results.

还有一件事:你可能要考虑使用位置属性,而不是codebase属性。该位置属性包含对在运行时加载的程序集的绝对路径。 codebase属性略有不同,而且可能不是在项目的整体构建所有组件相同。

One other thing: you may want to consider using the Location property instead of the CodeBase property. The Location property contains the absolute path to the assembly that was loaded at runtime. The CodeBase property is slightly different, and may not be the same for all assemblies in a full build of a project.

这篇关于不是所有的组件都被加载到AppDomain中bin文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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