4

Here is my code:

var s = new System.EnterpriseServices.Internal.Publish();
foreach (string file in Directory.EnumerateFiles(@"C:\Program Files\MyFolder\MSPractices"))
{
    Console.WriteLine("GACing " + file);
    s.GacInstall(file);
}

These are the files I'm trying to GAC (version 6.0.1304.0)

Microsoft.Practices.EnterpriseLibrary.Caching.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.EnterpriseLibrary.Data.dll Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll Microsoft.Practices.EnterpriseLibrary.Logging.dll Microsoft.Practices.EnterpriseLibrary.PolicyInjection.dll Microsoft.Practices.EnterpriseLibrary.Security.dll Microsoft.Practices.EnterpriseLibrary.Validation.dll Microsoft.Practices.ServiceLocation.dll Microsoft.Practices.Unity.Configuration.dll Microsoft.Practices.Unity.dll Microsoft.Practices.Unity.Interception.Configuration.dll Microsoft.Practices.Unity.Interception.dll

They were given to me by someone else so I'm not sure where you can get them but surely they're available online.

The code correctly outputs that list and does not throw any exceptions but running gacutil /l reveals that only a few of them (highlighted below) are actually installed.

enter image description here

What can be going wrong?

POSSIBLY IMPORTANT: My real issue is that this doesn't work in my InstallShield InstallScript installer with similar code (using the EnterpriseServices.Internal.Publish object).

UPDATE:

This method throws no exception! ...for anything! Publish pub = new Publish(); pub.GacInstall("foo");

No error, no exception. If the path is valid, and the assembly is strongly named, it will get properly installed in the GAC. Works for target .NET Frame version of assembly. I.e. a .NET Framework 4.0 app using GacInstall will properly install a 3.5 targeted assembly, etc.

Update (2011/12/13) - After using ILSpy to look at the code for this function, I did discover that errors are sent to the local machine's Event Viewer:

Unfortunately, all events in the event viewer say only

Installation in the global assembly cache failed: foo

sirdank
  • 3,351
  • 3
  • 25
  • 58

3 Answers3

2

You already came to the conclusion those methods are not always useful.

If you want a more robust method you can do it from C# using the GAC/Fusion API documented here and here. An example in C# can be found here (thanks to Hans Passant), here or here.

You might also try gacutil.exe to see what the problem is. You can find it on your machine with Visual Studio installed.

Community
  • 1
  • 1
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
1

It did turn out to be Installshield. Version 6 of the EnterpriseLibrary assemblies target .NET 4.0 and, because Installshield only builds 32-bit .exes, it was calling the .NET 2.0 System.EnterpriseServices .dll which couldn't register the .NET 4.0 EnterpriseLibrary assemblies. I've added a custom C# tool to publish the assemblies that is called via installscript. It's ugly but it'll have to do until we can convert to WIX.

sirdank
  • 3,351
  • 3
  • 25
  • 58
1

I had similar issue today; the machine had rebooted. I opened Powershell ISE in non-admin mode, ran the same script iI had run 100s of time, and it acted like it ran but it didn't. Issue was to open as Administrator.

NealWalters
  • 17,197
  • 42
  • 141
  • 251