Question

Here's the situation:

I have a DLL compiled in .NET 2 that goes in the global assembly cache. I have the myDLL.dll.config file which reads:

<configuration>
   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="myDLL" publicKeyToken="c426c33bab532523" />
        <bindingRedirect oldVersion="1.2.2.0-1.2.2.22" newVersion="1.2.2.23" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I then use the assembly linker to create the policy file:

al /link:myDLL.dll.config /out:policy.1.2.myDLL.dll /keyfile:myDLL.snk

But when I try to load the policy file into the global assembly cache using

gacutil -i policy.1.2.myDLL.dll

I get the error:

Failure adding assembly to the cache:  This assembly is built by a 
runtime newer than the currently loaded runtime and cannot be loaded.  

The .NET Global Assembly Cache Utility version is 2.0.50727.42, but I checked the version on the build environment by creating a new C# .NET 2 console project, and executing the following:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show(Environment.Version.ToString());
        }
    }
}

and my Environment.Version is 2.0.50727.5466.

This is all happening on the same computer, specifically, my dev box.

I can copy myDLL.dll from the \bin\release folder into c:\Windows\assembly folder, no problem. But trying to either copy-past the policy.1.2.myDLL.dll file from \bin\release to \assembly, or using gacutil fails.

Was it helpful?

Solution

The problem was that the policy assembly is being compiled for .NET 4.x.

There is an al.exe in %PROGRAMFILES(X86)%\Microsoft SDKs\Windows\v7.0A\Bin and another in %PROGRAMFILES(X86)%\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools. They both have the same version number, but the first is for .NET 2.x and the latter is for .NET 4.x. You should specify the full path to make sure you are using the right one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top