c# - 如何防止 .NET 应用程序从 GAC 加载/引用程序集?

标签 c# .net assemblies gac

我能否以引用“本地”程序集(不在 GAC 中)而不是 GAC 中的程序集的方式(Visual Studio 中的设置)配置 .NET 应用程序,尽管这两个程序集具有相同的名称和同一个版本?

最佳答案

如果两个程序集都具有强名称(已签名),则 CLR 将始终从 GAC 加载。

以下是运行时用于解析程序集引用的步骤(来自 How the Runtime Locates Assemblies ):

  1. Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first.

  2. Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. If a previous request to load the assembly failed, the request fails immediately without attempting to load the assembly.

  3. Checks the global assembly cache. If the assembly is found there, the runtime uses this assembly.

  4. Probes for the assembly (... some material omitted ...)

如后文所述:

There is no version checking for assemblies without strong names, nor does the runtime check in the global assembly cache for assemblies without strong names.

因此,如果您有能力从本地程序集中删除签名,应用程序将使用它而不是 GAC 中的签名。

有关运行时绑定(bind)机制的更多详细信息,请参阅 Suzanne Cook's blog .

This blog entry from Scott Hanselman还对绑定(bind)过程进行了很好的概述。

关于c# - 如何防止 .NET 应用程序从 GAC 加载/引用程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1606867/

相关文章:

c# - 更改对象形式后更新数据库序列化对象的最佳方法

c# - IIS 安装在 Windows 10 的 D 分区上

c# - 验证 base64 编码图像 .NET 核心

c# - 无法停止异步 TCP 服务器 Windows 服务

c# - 检查装配体的身份?可能是因为它的强大名称?

javascript - 关闭在 WPF WebBrowser 中运行的网页

.net - 在 Entity Framework 4 中使用带有额外参数的存储过程的策略

c# - 来自数据库的通知而不是轮询。是否可以?

.net - 了解 Windows 中的 AppDomain

c# - 使用同一程序集的不同版本