Hello,
I'm installing a .NET class library using a Visual Studio Setup Project
template.
The class library is installed to program files\myclass\myclass.dll.
In order to add myclass.dll to the GAC and to register it for COM Interop,
my class library project contains an installer class with code listed below.
In order to execute the code within the installer class, 'Application
folder\myclass.dll" has been added to the following custom actions in the
Setup Project: Install, Commit, and Uninstall.
My class installs correctly and the custom action correctly adds it to the
GAC.
When uninstalling, I get the following error:
Unable to delete file
C:\Windows\assembly\GAC_MSIL\MyClass\1.1.2345.5789_...\MyClass.InstallState.
Please note that MyClass.InstallState file is located in program
files\MyClass and not in the GAC.
<Security.Permissions.SecurityPermission(Security.Permissions.SecurityAction.Demand)>_ Public Overrides Sub Commit(ByVal savedState AsSystem.Collections.IDictionary) Dim oPub As Internal.Publish = New Internal.Publish Dim sDllPath As String =System.Reflection.Assembly.GetExecutingAssembly.Location 'add assembly to GAC oPub.GacInstall(sDllPath) 'register assembly oPub.RegisterAssembly(sDllPath) MyBase.Commit(savedState) End Sub <Security.Permissions.SecurityPermission(Security.Permissions.SecurityAction.Demand)> _ Public Overrides Sub Uninstall(ByVal savedState AsSystem.Collections.IDictionary) Dim oPub As Internal.Publish = New Internal.Publish Dim sDllPath As String =System.Reflection.Assembly.GetExecutingAssembly.Location 'unregister assembly oPub.UnRegisterAssembly(sDllPath) 'remove assembly from GAC oPub.GacRemove(sDllPath) MyBase.Uninstall(savedState) End SubRegards,
Steven Cheng[MSFT] - 04 Dec 2007 07:05 GMT
Hi,
Regarding on this issue, I've found your another new post in this newsgroup
and have replied you there. Welcome to continue followup there.
Thanks for your posting!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "gINT Developer" <gintdeveloper@community.nospam>
>Subject: Installer Custom Actions Problem VS.2005
[quoted text clipped - 16 lines]
>Unable to delete file
>C:\Windows\assembly\GAC_MSIL\MyClass\1.1.2345.5789_...\MyClass.InstallState
Phil Wilson - 04 Dec 2007 19:20 GMT
The big picture issue is that you don't need to be doing any of this. The
setup project can install (and uninstall) into the GAC just fine (you'll
need to Add Special Folder in the File System View to add the GAC to the
list). Just do that and dump all this unnecessary code.
In your uninstall case, what seems to be happening is that your assembly is
being loaded from the GAC ( because I think you're installing it locally and
then your code installs it into the GAC, and the GAC copy will be loaded
first). Once the GAC assembly is loaded into the process the rest of the
mechanism fails. There's a ton of infrastructure that expects to load your
assembly from program files but the GAC one is already loaded, so it wants
to find installstate from the same location as the assembly.
There is no support in Windows Installer for managed code custom actions.
Installer classes work by having a C++ Dll loaded into the install process
(msiexec.exe) which loads the CLR into the process, loads your assembly,
reflects on it to find installer classes, instantiates and calls methods.
Because it's so dependent on loading assemblies it can be fragile.
http://support.microsoft.com/kb/906766/en-us describes a similar case where
loading assemblies for installer class custom actions picks up the wrong one
because an identical assembly is already loaded.

Signature
Phil Wilson
[MVP Windows Installer]
> Hello,
>
[quoted text clipped - 31 lines]
> assembly oPub.UnRegisterAssembly(sDllPath) 'remove assembly from GAC
> oPub.GacRemove(sDllPath) MyBase.Uninstall(savedState) End SubRegards,