Recently I’ve stumbled into an error on updating Assemblies within the GAC. The error occured on updating Assemblies within the GAC through updating via new DLLs within a CAB File.
Obviously the files were registered properly, but during runtime MissingMethodExceptions were thrown.
Therefore I created a little (specific) tool, which cleans the Registry and GAC Assemblies .Let’s assume, we have the file MyAssembly.dll registered and use the file MyAssembly.gac:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using Microsoft.Win32;
using System.Windows.Forms;
namespace CleanRegistry
{
class Program
{
static void Main(string[] args)
{
try
{
RegistryKey regMain = Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\.NETCompactFramework\Installer\Assemblies", true);
if (regMain == null)
{
return;
}
RegistryKey regTemp = regMain.OpenSubKey(@"3rdParty", true);
regTemp.DeleteSubKey(@"MyAssembly.gac", false);
regTemp.Flush();
regTemp.Close();
regTemp = regMain.OpenSubKey(@"Global", true);
foreach (string valueName in regTemp.GetValueNames())
{
if (valueName.StartsWith("MyAssembly"))
{
regTemp.DeleteValue(valueName, false);
}
}
regTemp.Flush();
regTemp.Close();
regTemp = regMain.OpenSubKey(@"Reference", true);
foreach (string subKeyName in regTemp.GetSubKeyNames())
{
if (subKeyName.StartsWith("MyAssembly"))
{
regTemp.DeleteSubKeyTree(subKeyName);
}
}
regTemp.Flush();
regTemp.Close();
foreach (string filename in Directory.GetFiles(@"\Windows", "GAC_MyAssembly.*.dll"))
{
FileInfo fi = new FileInfo(filename);
fi.Attributes = FileAttributes.Normal;
fi.Delete();
}
MessageBox.Show("The cleaning was successfull.", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
catch
{
MessageBox.Show("The cleaning was NOT successfull.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
}
}
}
If you want to know more about the .NET CF GAC, I propse you shall read these articles.