Installing .NET 4.0 Assemblies to the Global Assembly Cache (GAC)

0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×

I had an interesting problem today which helped me learn a little about some changes to the way .NET 4.0 assemblies are handled. I was passed a couple of .NET 4.0 assemblies to add to the GAC on one of our windows 2008 x64 servers. I didn’t think much of it until I got started!

I first started by trying to install the assemblies using the gacutil batch script I’d always been using – it looked something like this:

This all looks fine and is what you’d expect – I’d copied the gacutil from “C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin” on my dev machine to the same directory as the batch file (on the server) and then executed the batch file. I was then presented with the following error:

At this point I double checked that the .NET framework 4.0 was installed (which it was). It turns out that for .NET framework 4 assemblies, you have to use the newer gacutil, installed with Microsoft Windows SDK for Windows 7 and .NET Framework 4, found here:

So I installed the aforementioned SDK, got the newer gacutil (from C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\)and attempted again. This time I got no errors, but also no confirmation that the assembly was installed in the GAC. So I checked the GAC (%windir%\windows\assembly), and found that the assembly had not installed!

After a little more digging I found that the .NET framework 4.0 introduced a NEW GAC, meaning we have 2 GACs to manage – one for .net 2.0-3.5, and one for .net 4.0. The new .net framework 4.0 gac is located at %windir%\Microsoft.NET\assembly\ – so I checked this and to my shock, the assembly was not installed in there either!

Finally, I found my answer from MarkdeCates in this forum post: It seems that as well as copying the gacutil.exe, we also need to copy gacutil.exe.config and gacutlrc.dll (which is located in the 1033 subfolder). If these additional files are not copied, the gacutil doesn’t throw an error…in fact it doesn’t do anything.

So I finally got there, albeit a little confused!!


, ,

  • Fadi Khoury

    Thanks a lot! 🙂

  • Tan Kiat Yao

    I already followed your instructions. But it still returns me with an error message. “Failure adding assembly to the cache”

  • Samra

    Hi Matt, I have an even more complicated scenario! I have a VM on which multiple versions of Visual studio and .net framework are installed. I am using vs 2013 and apparently v4.0.
    i have tried running gacutil by running
    c:/Program Files(x86)/Microsoft Visual Studio 12.0/Common7/Tools/vsDevCmd.bat
    after which when i try to uninstall my assembly, it says i need admin privileges although i already have them.!!

    • Samra

      Well i simply had to right-click command prompt and click run as administrator and then do the uninstall!! 😀

      • Sorry I hadn’t replied – was on holiday! Glad to hear you got it sorted!

  • mrityunjaya tiwari

    Hi Matt, I have a different problem, I have created the dll’s and installed them in GAC, it was successful, then I wanted to use policy file dll’s to redirect to newer version of dll’s, so I have created the policy files and for .Net applications it is redirecting to newer versions, but when i am trying to add the assemblies in SQL SERVER 2012 it is giving me error “Assembly ‘DLLName’ could not be installed because existing policy would keep it from being used.” although i am using the dll’s build with .Net 4.0.

    • I’ve not really done much with policy files I’m afraid. Could it be anything to do with x86 vs x64 versions?

      • mrityunjaya tiwari

        Thanks for the reply Matt, No it is not related to x86 or x64 but it is related to redirecting the applications to newer version, suppose i have built one exe “Sample.exe” with a dll name “Xyz”(version 1.0.0) then i have updated the “Xyz” to ( and I want that “Sample.exe” automatically use the version version although it is build with ( In this scenario the policy file redirect us to newer version.

        • Sorry I should clarify, I do understand what you’re trying to achieve using the policies.

          I was just wondering if the problem is related to the assembly being compiled as x64, when SQL server is only running as x86

          • mrityunjaya tiwari


The Essential App Marketing Kit
Subscribe To My Newsletter To Get an Entire Chapter From The Book for FREE
Never display this again
0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×