Je voudrais pouvoir installer/désinstaller des assemblies dynamquement dans le GAC. Pour ce qui est de l'installation, elle marche nikel avec ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
public void AddtoGAC()
        {
            // Get the assembly location
            string location = GetAssembly().Location;
            // Get the assembly cache interface.
            IAssemblyCache assemblyCache = null;
            int hr = CreateAssemblyCache(out assemblyCache, 0);
            if (0 != hr)
                throw new ApplicationException("Failed to get AssemblyCache interface!");
            // Install the assembly
            hr = assemblyCache.InstallAssembly(0, location, (IntPtr)0);
            if (0 != hr)
                throw new ApplicationException("Failed to add this assembly to the GAC!");
        }
IAssemblyCache correspondant à l'interface vers Fusion.dll :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("e707dcde-d1cd-11d2-bab9-00c04f8eceae")]
    internal interface IAssemblyCache
    {
        ///
        [PreserveSig()]
        int UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr pvReserved, out uint pulDisposition);
        [PreserveSig()]
        int QueryAssemblyInfo(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr pAsmInfo);
        [PreserveSig()]
        int CreateAssemblyCacheItem(uint dwFlags, IntPtr pvReserved, out /*IAssemblyCacheItem*/IntPtr ppAsmItem, [MarshalAs(UnmanagedType.LPWStr)] String pszAssemblyName);
        [PreserveSig()]
        int CreateAssemblyScavenger(out object ppAsmScavenger);
        [PreserveSig()]
        int InstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszManifestFilePath, IntPtr pvReserved);
    }
Mais mon problème est que la désinstallation échoue toujours à partir de mon programme ( bien que je puisse désinstaller l'assembly à partir du shell de Windows ) avec une erreur IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED bien que cette assembly soit toujours listée dans le shell .
Pour la désinstaller j'utilise ce code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
public void RemoveFromGAC()
        {
            // Get the full assembly name
            string fullName = GetAssembly().FullName;
            // Get the assembly cache interface.
            IAssemblyCache assemblyCache = null;
            int hr = CreateAssemblyCache(out assemblyCache, 0);
            if (0 != hr)
                throw new ApplicationException("Failed to get AssemblyCache interface!");
            // Remove the assembly
            uint n = 0;
            hr = assemblyCache.UninstallAssembly(0, fullName, (IntPtr)0, out n);
            if (0 != hr)
            {
                IASSEMBLYCACHE_UNINSTAL_ID id = IASSEMBLYCACHE_UNINSTAL_ID.Unknown;
                if (Enum.IsDefined(typeof(IASSEMBLYCACHE_UNINSTAL_ID), n))
                    id = (IASSEMBLYCACHE_UNINSTAL_ID)n;
 
                throw new ApplicationException(String.Format("Failed to remove this assembly from the GAC!\nError : {0}",id));
            }
        }
Je voudrais donc savoir quel sont les causes possibles d'une érreur IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED, ou encore, comment je pourrai parvenir à installer/désinstaller l'assembly du GAC, sans utiliser GacUtil.exe ... auriez - vous une idée ?

Cdl
Smyley