2

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()); 

Output:

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

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?

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:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under executable C:\Programs\Tools\ConnectionTester_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:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Publisher policy file is found at C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Policy.4.121.Oracle.ManagedDataAccess\v4.0_4.122.1.0__89b483f429c47342\Policy.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:\Windows\Microsoft.Net\assembly\GAC_MSIL\Oracle.ManagedDataAccess\v4.0_4.122.1.0__89b483f429c47342\Oracle.ManagedDataAccess.dll. LOG: Assembly is loaded in default load context. 

It looks as expected, saying

Publisher policy file redirect is found: 4.121.1.0 redirected to 4.122.1.0.

but I like to bypass it.

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> 
2
  • Use fuslogvw.exe, log all binds. Show the trace in your question. Commented Jun 29, 2017 at 9:00
  • @HansPassant, added log Commented Jun 29, 2017 at 9:27

1 Answer 1

1

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

<publisherPolicy apply="no" /> 

more info here and here

Sign up to request clarification or add additional context in comments.

1 Comment

<publisherPolicy apply="no" /> is working, however setting <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects> did not change anything.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.