microsoft / msix-packaging

MSIX SDK
MIT License
963 stars 163 forks source link

[BUG] Windows service not installed #558

Closed Mathyn closed 1 year ago

Mathyn commented 1 year ago

Project MSIX SDK

Describe the bug We have a MAUI app packaged as an MSIX which includes a Windows service. However we are getting bug reports which indicate the service is not running. Research shows that the service is missing for some users.

After some debugging we found that if you uninstall any version of our app and then reinstall it again the service is not created.

Looking through the eventviewer at the logs for the AppXDeployment-Server I see the following warning in the scenario the service is missing:

OpenService for service OurCompanyNameVpnManager failed with error 0x80070424.

To Reproduce

  1. Install an MSIX with a service
  2. Check your services, service should be there
  3. Uninstall the MSIX (service is gone now)
  4. Reinstall the MSIX again
  5. Check your services, service is missing now

No amount of reboots, uninstalls/reinstalls will fix the system for me now. The only way to fix it is to install a different version of the app. Don't know why but either a version downgrade or upgrade seems to register the service again.

Expected behavior Uninstall the app should remove the service, reinstalling the same version should then add the service again.

Platform

Verified on Windows 10 and Windows 11.

Additional context

Our appxmanifest looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
  xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
  IgnorableNamespaces="uap rescap">

  <Identity Name="OurCompanyName" Publisher="CN=OurCompanyName B.v." Version="0.0.0.0" />

  <Properties>
    <DisplayName>OurCompanyName</DisplayName>
    <PublisherDisplayName>OurCompanyName B.v.</PublisherDisplayName>
    <Logo>$placeholder$.png</Logo>
  </Properties>

  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
    <PackageDependency Name="Microsoft.VCLibs.140.00.UWPDesktop" MinVersion="14.0.24217.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
  </Dependencies>

  <Resources>
    <Resource Language="x-generate" />
  </Resources>

  <Applications>
    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
      <uap:VisualElements
        DisplayName="$placeholder$"
        Description="$placeholder$"
        Square150x150Logo="$placeholder$.png"
        Square44x44Logo="$placeholder$.png"
        BackgroundColor="transparent">
        <uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />
        <uap:SplashScreen Image="$placeholder$.png" />
      </uap:VisualElements>
      <Extensions>
          <desktop:Extension Category="windows.startupTask" Executable="OurCompanyName.exe" EntryPoint="MauiProgram.CreateMauiApp">
            <desktop:StartupTask TaskId="OurCompanyName" Enabled="true" DisplayName="OurCompanyName" />
          </desktop:Extension>
          <desktop6:Extension
          Category="windows.service"      
          Executable="OurCompanyNameService.exe"
          EntryPoint="OurCompanyNameService.Program">
            <desktop6:Service
              Name="OurCompanyNameVpnManager"
              StartupType="auto"
              StartAccount="localSystem"
              Arguments="/manage"
          >
          </desktop6:Service>
        </desktop6:Extension>
      </Extensions>
    </Application>
  </Applications>

  <Capabilities>
    <rescap:Capability Name="runFullTrust" />
    <rescap:Capability Name="allowElevation" />
    <rescap:Capability Name="packagedServices" />
    <rescap:Capability Name="packageManagement" />
    <rescap:Capability Name="localSystemServices" />
  </Capabilities>

</Package>
strayans commented 1 year ago

We are looking into this issue. @prkhandelwal-msft

prkhandelwal-msft commented 1 year ago

Seems like an app specific issue, I converted an app(different from the one mentioned in the post) that requires windows service using latest version of MSIX Packaging Tool and tried to reinstall MSIX and I was able to find the service that is packaged among all the windows service.

Mathyn commented 1 year ago

Hi, thanks for your reply. I'll run some more tests and see if I can produce a minimal example proving/disproving this issue.

Mathyn commented 1 year ago

@prkhandelwal-msft just to clarify about the reproduction steps. If I simply reinstall the app things work fine. What causes issues for me though are these steps:

After following these steps it fails to reinstall the service.

Can you verify the app you used for testing also works in this scenario?

prkhandelwal-msft commented 1 year ago

@Mathyn I followed the same steps mentioned, the app I used was LogmeIn Hamachi, it creates a service called hamachi-2 upon installing. On uninstalling via Windows Apps and Features in settings the service got removed from the list and on reinstalling i was successfully able to install the app again and the service was again visible in the list.

Mathyn commented 1 year ago

@prkhandelwal-msft clear, thank you for double checking. I'll work on a minimal example next week and I'll update this post with my findings.

Mathyn commented 1 year ago

Hi, I've created a minimal example which you can find here https://github.com/Mathyn/TestMauiAppWithService

You may need to add your own local signing certificate before publishing. I've tried to stay as close as possible to the templates provided by Microsoft.

I've used the following templates:

To reproduce:

This time however I got an error while installing. I've seen this happen a couple of times with the original app as well but after some time these disappeared again (and instead I get the error where a service was not installed).

When installing the second time I get the following error:

App installation failed with error message: AppX Deployment operation failed with error 0x0 from API Logging data because access was denied for file: \\?\C:\Program Files\WindowsApps\C1964CB7-9D0F-4355-9225-4A4ADDE15BC1_0.0.1.0_x64__43bca71cbdt9w\AppxManifest.xml, user SID: S-1-5-18 (0x80070005)

Navigating to the folder in WindowsApps shows several files still remaining. I can manually delete this except for one: AppxManifest.xml. The only way to get this file off my system is rebooting my PC, after rebooting I can reinstall the test app again. I can redo these steps as often as I want and produce the same result.

Trying to install the app via Powershell as administrator using Add-AppxPackage also yields the same result.

Did some further testing on a clean Windows 10 installation (using a virtual machine hosted with Hyper-V) and found that the installation folder does get properly removed there and installing and uninstalling works just fine. On this clean machine the service also gets installed properly so I'd say it should work but for some reason on some Windows PCs it just doesn't.

Checking back with the original app I can see it also does not remove the installation folder on uninstall. This may be on purpose but I'm wondering if this could explain something?

Please let me know if I can provide any more information to debug this. On my side my client is committed to solving this and will allocate time if needed.

prkhandelwal-msft commented 1 year ago

Hey, I build your project and published it to MSIX using the dot net publish command (I also tried publishing it via visual studio 2022 but it failed showing this error MSB4057 The target "_GenerateAppxPackage" does not exist in the project. but running your command worked and I got the output MSIX. I followed the following steps then -

I tested it again just to verify once more but the issue is not reproducible at my end. Also can you check before first time installing the MSIX, is the service already present in the system because if an unpackaged version of service is present in the system then adding the same service through MSIX fails. Although the error message that I know is different as compared to this but can you still verify?

Mathyn commented 1 year ago

Hi, thank you for taking the time to verify this!

Quick note about the issues you did encounter:

I've checked to see if a service was already present before installation. This was not the case though.

I did find a potential cause last week. We recently finished work on upgrading the project from .NET 6 to .NET 7 (and from WindowsAppRunTime 1.1 to 1.2 as a consequence). We found we could no longer reproduce the issue on our Windows 11 test system after the upgrade. I also verified I could no longer reproduce it on a clean Windows 10 VM. Locally however on my system (Windows 10) issues remain.

I uninstalled all instances of the WindowsAppRunTime on my machine and reinstalled 1.2 again but this did not work.

With this latest information I am unsure how to proceed with this ticket. It could be related to using the old 1.1 runtime. The issues still remaining on my system I can't explain but it might be a very specific local issue.

@prkhandelwal-msft what do you think? Do you have any ideas to further debug this? Otherwise we can also consider closing this for now.

prkhandelwal-msft commented 1 year ago

Hey @Mathyn, just to add, today i tried reproducing the same in windows 10 hyper-v clean environment. There too upon uninstalling the service was getting removed as well, but in win10 this test app was not launching. My guess would be there must be something in your local system that is inhibiting the service to not get uninstalled because this kind of behavior is not generally seen with MSIX. What I can think of is that as this service that you created in the TestMauiApp runs as a local system, your user account may not be able to uninstall it. You can test uninstalling any service that runs as a local system manually and verify it.

Can you try to do one more thing at your end, -

Also I think you can close this issue as well for now.

Mathyn commented 1 year ago

Hi, double checked and the service does get uninstalled properly so whatever issue my system seems to have it only pop ups once I reinstall things again.

I'm going to chalk this up to a combination of my system and using an outdated WindowsAppRunTime.

I checked gpedit.msc and the setting is set to 'Not Configured'. Was there anything specific you wanted me to check or configure?

angelru commented 9 months ago

@Mathyn Did you get it to work?