Hello,
I am making a simple WPF graphical installer for a Windows Service, and need to call Installer.Install() directly from the InstallerGUI.
Here is the rather trivial definition of the derived Installer:
public class ProjectInstaller : System.Configuration.Install.Installer
{
private ServiceInstaller serviceInstaller1;
private ServiceProcessInstaller processInstaller;
public ProjectInstaller()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller1 = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller1.StartType = ServiceStartMode.Automatic;
serviceInstaller1.ServiceName = "SiroonianMonitorService";
Installers.Add(serviceInstaller1);
Installers.Add(processInstaller);
}
}
And here is the exception I get when calling Install():
System.NullReferenceException: Object reference not set to an instance of an object.
at System.ServiceProcess.ServiceInstaller.Install(IDictionary stateSaver)
at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
at InstallerGUI.Pages.ViewModels.InstallationViewModel.DoInstall(Object sender, DoWorkEventArgs e) in C:\Users\dstevens\src\MonitoringDeviceProject\MonDevService\InstallerGUI\Pages\ViewModels\InstallationViewModel.cs:line 97
I'm pretty stumped, I don't know why this is happening. I made sure the ServiceName of my service class that derives from ServiceBase is also "SiroonianMonitorService". Any other ideas why this might be occurring would be immensely helpful!
Thank you,
Derek
EDIT: I have made a new solution from scratch to test and make sure I didn't get anything twisted, and I get the same results (.NET Framework 4.7.2):
Startup project InstallerWrapper:
using testService;
using System.Collections;
namespace InstallerWrapper
{
public class Program
{
static void Main()
{
TestInstaller self = new TestInstaller();
self.Install(new Hashtable());
}
}
}
Implementation project testService:
namespace testService
{
public class TestService : ServiceBase
{
public TestService()
{
ServiceName = "TestService";
}
public static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new TestService()
};
ServiceBase.Run(ServicesToRun);
}
}
public class TestInstaller : Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public TestInstaller()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.Context = new InstallContext();
serviceInstaller.Parent = processInstaller;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "TestService";
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
}