Bypassing publisher policy files

When resolving a strong named assembly, the GAC is the first place looked up, not the /bin folder. Publisher policy files if present in the GAC will redirect the request to a newer version of the assembly. Only if the GAC lookup is unsuccessful the application bin folder is looked up.

For instance, Oracle.DataAccess 4.112.1.2 is a strong named assembly that is not installed in the GAC by default. Applications referring this assembly will fail to load unless we install the assembly in the GAC using the gacutil command-line utility. Alternatively, we can copy the assembly to the bin folder by setting the Copy Local property to true.

######Disable Policy Files for All Assemblies in the App.Config File

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!-- DISABLE GAC POLICY FILES -->
      <publisherPolicy apply="no" />
    </assemblyBinding>
  </runtime>
</configuration>

######Disable Policy Files for a Specific Assembly in the App.Config File

The configuration below shows how to redirect all requests for Oracle.DataAccess.dll to 2.112.1.2 for version in the range 0.0.0.0-65535.65535.65535.65535.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <!-- DISABLE GAC POLICY FILES -->
        <publisherPolicy apply="no" />
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.112.1.2"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Note:

  • If the <publisherPolicy> element is not present or apply is set to ‘yes’, the redirect in the GAC policy will apply
  • Valid values for each part of the version number are 0 to 65535.
  • The publicKeyToken and culture are required. If these attributes are omitted or are set to blank or null, the redirect will have no effect

######Assembly Binding Log Viewer (Fuslogvw.exe)

[From MSDN:](https://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx?tduid=(9f7dcf4661682586f98985177f4ba79a) The Assembly Binding Log Viewer displays details for failed assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location or a mismatch in version numbers or cultures. The common language runtime’s failure to locate an assembly typically shows up as a TypeLoadException in your application.

The FUSLOGVW.exe utility can be found at these locations:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

for 64-bit..

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64

This following sample log shows a succeeded assembly bind for Oracle.DataAccess.dll. The application comes looking for version 2.111.6.20 and due to the redirect, gets served 2.111.6.0 instead. I have highlighted the most relevant entries.

*** Assembly Binder Log Entry  (5/25/2011 @ 10:42:42 PM) ***
The operation was successful. Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows.= Pre-bind state information =
LOG: User = IIS APPPOOL\Classic .NET AppPool
LOG: DisplayName = Oracle.DataAccess, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342 (Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/hello/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\hello\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\hello\f5bd5b60
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\hello\f5bd5b60
LOG: AppName = 18c658a8
Calling assembly : MyAssembly.HelloWorld, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\hello\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Redirect found in application configuration file: 2.111.6.20 redirected to 2.111.6.0.
LOG: Safe mode is set (publisher policy disallowed). 
LOG: Post-policy reference: Oracle.DataAccess, Version=2.111.6.0, Culture=neutral, PublicKeyToken=89b483f429c47342 
LOG: Found assembly by looking in the GAC. 
LOG: Binding succeeds. Returns assembly from C:\Windows\assembly\GAC_32\Oracle.DataAccess\2.111.6.0__89b483f429c47342\Oracle.DataAccess.dll.
LOG: Assembly is loaded in default load context.