unable to start windows service after installing using msi

0

I've created a windows service project. In the post build event, I am copying the output to outside one common directory along with one more project. I am generating a MSI using heat task to copy both directories inside MSI. I'm trying to start service after installation.

Both projects use serilog.configuration to load json file which has logger configuration.

If I install service with the help of installutil, service is installed successfully and starts afterwards perfectly. but when I try to install using MSI, I get below error and installation never finishes.

Service cannot be started. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at Hive.WindowsAgent.Service.HiveAgentService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

I checked nuget package, windows service has Microsoft.Extensions.Configuration.Abstraction v3.1.5 included. And it fails only with MSI.

my wix file:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="$(var.ProductName)" Language="1033" Version="$(var.ProductVersion)" Manufacturer="$(var.ProductManufacturer)" UpgradeCode="$(var.ProductUpgradeId)">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />
    <Feature Id="ProductFeature" Title="HarvestSetup" Level="1">
      <ComponentGroupRef Id="AutogeneratedComponents" />
      <ComponentGroupRef Id="ProductComponents"/>
    </Feature>
    <UI />
  </Product>
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFiles64Folder">
        <Directory Id="INSTALLFOLDER" Name="$(var.ProductManufacturer)" ComponentGuidGenerationSeed="4BDDE809-FF2B-4DF9-B1D6-2DBA45AB122F">
        </Directory>
      </Directory>
    </Directory>
  </Fragment>
  <Fragment>
    <DirectoryRef Id="INSTALLFOLDER">
      <Directory Id="HiveServiceDirectory" Name="HiveService" />
    </DirectoryRef>
    <ComponentGroup Id="ProductComponents"  Directory="HiveServiceDirectory">
      <Component Id="ProductServiceInstaller" Guid="4F512FED-176D-4FBE-AAC2-8333E4B4231F">
        <File Id="$(var.ServiceName)" Name="$(var.ServiceName)" Source="$(var.ProductPath)" KeyPath="yes" />
        <ServiceInstall Id="ServiceInstaller"
                        Type="ownProcess"
                        Name="$(var.ServiceName)"
                        DisplayName="$(var.ServiceName)"
                        Description="Service for Windows agent"
                        Start="auto"
                        Account="LocalSystem"
                        ErrorControl="normal" />
        <ServiceControl Id="StartStopService"
                        Start="install"
                        Stop="both"
                        Remove="uninstall"
                        Name="$(var.ServiceName)"
                        Wait="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

What am I missing?

P.S. Let me know if anymore information is needed

c#
wix
windows-services
asked on Stack Overflow Jul 14, 2020 by Pratik Gaikwad • edited Jul 14, 2020 by Pratik Gaikwad

2 Answers

0

In your csproj file add:

   <PropertyGroup>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
   </PropertyGroup>

there's an issue with auto-generated binding redirects.

This should force MSBuild to create / update a YourProject.dll.config file containing the necessary binding redirects.

answered on Stack Overflow Jul 14, 2020 by D A
0

It was the stupidest thing i could think of. Fortunately I had received a lot of help from Kevin and Alex on .net slack group.

All I was missing exe extension in <File Id="$(var.ServiceName)" Name="$(var.ServiceName)" Source="$(var.ProductPath)" KeyPath="yes" />

Ultimately the line should be

<File Id="$(var.ServiceName)" Name="$(var.ServiceName).exe" Source="$(var.ProductPath)" KeyPath="yes" />
answered on Stack Overflow Jul 14, 2020 by Pratik Gaikwad

User contributions licensed under CC BY-SA 3.0