C# System.Configuration.Install rollback() function does not work

Michael Villarin 1 Reputation point
2022-06-08T09:09:07.923+00:00

I am trying to implement a rollback function in my installer file but it doesn't work. My intention is that if a certain process is still running, the uninstallation should roll back (program should still be listed in list of apps and programs) but overriding the Rollback() function doesn't seem to do anything.

public override void Rollback(IDictionary savedState)  
{  
  base.Rollback(savedState);  
  
}  

The Rollback function is called in Uninstall, when a particular process is detected to be still running:

public override void Uninstall(IDictionary savedState)  
    {  
            var ret = CheckIfProcessRunning();  
            if (ret)  
            {  
                Console.WriteLine("Uninstallation will complete with error");  
                base.Rollback(savedState);  
            }  

This code does not roll back when the conditions are fulfilled. However, if I throw an exception that is not handled, the installation will roll back.

public override void Uninstall(IDictionary savedState)  
    {  
            var ret = CheckIfProcessRunning();  
            if (ret)  
            {  
                Console.WriteLine("Uninstallation will complete with error");  
                throw new InstallException("Installation will abort.");  
            }  

But this is not the method I want to use, I want to roll back without throwing the exception. Thanks in advance

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,288 questions
{count} votes