4

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.

CurtisHx
  • 746
  • 3
  • 11
  • 30
  • http://social.msdn.microsoft.com/Forums/en-US/biztalkgeneral/thread/e76f5c46-e679-4923-bf9d-1f883074eb2e/ ? – Justin Pihony Jun 12 '13 at 14:47
  • Are you sure you are using the .NET 2.x version of al? – Tim B Jun 12 '13 at 14:56
  • @TimB I'm not sure. I opened up a new Visual Studio 2010 Command Prompt, typed in "al", and got `Assembly Linker version 10.0.30319.1`. I'm a bit new when it comes to working with dlls in the global assembly cache. – CurtisHx Jun 12 '13 at 15:02
  • 2
    You should have 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. I would specify the full path to make sure you are using the right one. – Tim B Jun 12 '13 at 15:05
  • 1
    @TimB, you solved my problem. Now I get to go explain to my boss why I wasted half a day working on this *$%! thing. – CurtisHx Jun 12 '13 at 17:25

1 Answers1

6

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.

Tim B
  • 2,340
  • 15
  • 21