本文介绍了如何从 GAC 加载特定版本的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,我喜欢从 GAC 加载特定版本的 DLL 程序集.但是,我的程序总是加载最新版本 - 我认为是由策略程序集驱动的.

For testing purpose I like to load a specific version of an DLL assembly from GAC. However, my program always load the latest version - I think driven by Policy Assemblies.

var dll = Assembly.Load("Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342");
Console.WriteLine(dll.ToString());

输出:

Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342

即使我在强名称中指定版本4.121.1.0",它也会加载版本4.122.1.0".有没有办法强制特定版本?

Even though I specify version "4.121.1.0" in strong name it loads version "4.122.1.0". Is there a way to force a specific version?

来自 fuslogvw.exe 的结果,如评论中所要求:

Result from fuslogvw.exe as requested in comment:

*** Assembly Binder Log Entry  (29.06.2017 @ 11:24:15) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll
Running under executable  C:ProgramsToolsConnectionTester_x64.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342
 (Fully-specified)
LOG: Appbase = file:///C:/Programs/Tools/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ConnectionTester_x64.exe
Calling assembly : ConnectionTester_x64, Version=1.0.353.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config.
LOG: Publisher policy file is found at C:WindowsMicrosoft.NetassemblyGAC_MSILPolicy.4.121.Oracle.ManagedDataAccessv4.0_4.122.1.0__89b483f429c47342Policy.4.121.Oracle.ManagedDataAccess.config.
LOG: Publisher policy file redirect is found: 4.121.1.0 redirected to 4.122.1.0.
LOG: ProcessorArchitecture is locked to MSIL.
LOG: Post-policy reference: Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:WindowsMicrosoft.NetassemblyGAC_MSILOracle.ManagedDataAccessv4.0_4.122.1.0__89b483f429c47342Oracle.ManagedDataAccess.dll.
LOG: Assembly is loaded in default load context.

它看起来像预期的那样,说

It looks as expected, saying

发现发布者政策文件重定向:4.121.1.0 重定向到 4.122.1.0.

但我喜欢绕过它.

版本 4.121.1.0 已安装在 GAC 中:

Version 4.121.1.0 is installed in GAC:

C:Program Files (x86)Microsoft Visual Studio 11.0>gacutil /l Oracle.ManagedDataAccess
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.18020
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
  Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL
  Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL

Number of items = 3

C:Program Files (x86)Microsoft Visual Studio 11.0>

推荐答案

您可能不得不绕过发布者政策.将您的应用程序配置文件添加到dependentAssembly

you probably will have to bypass the publisher policy.Add to your application configuration file to the dependentAssembly

<publisherPolicy apply="no" />

更多信息这里这里

这篇关于如何从 GAC 加载特定版本的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:13