Search code examples
c#angular.net-coreangular-cliazure-service-fabric

Error in Angular app running on .NET Core in Service Fabric


I have created a new service fabric application, added a stateless .NET Core service (.NET Core 2.1) and selected the angular template. It builds fine and all looks OK however when I run it I get this error:

enter image description here

Startup.cs contains a line spa.UseAngularCliServer(npmScript: "start"); which is only used in development, if I remove this line then I no longer get this error but it doesn't pick up any of my changes to code.

I have tried updating my npm, node, angular cli versions, updating the project to angular 7 (it is 5 by default) with no luck.

If I run ng serve directly in the ClientApp folder it runs OK so the issue seems to be to do with it being hosted in .NET Core or SF.

It seems it could be something to do with the SF service not having permissions to create/edit files/folders under system32?


Solution

  • As suspected it was to do with SF not having permission to modify that folder. Service fabric runs under the user NETWORK SERVICE.

    I found 2 ways to fix it:

    1. Manually grant permission to NETWORK SERVICE

    I navigated to C:\Windows\System32\config\systemprofile\AppData\Roaming and edited the permissions in that folder to give the user NETWORK SERVICE permissions to read/write

    2. Edit ApplicationManifest.xml to give SF admin permissions

    By adding

    <Principals>
      <Users>
        <User Name="LocalAdmin" AccountType="NetworkService">
          <MemberOf>
            <SystemGroup Name="Administrators" />
          </MemberOf>
        </User>
      </Users>
    </Principals>
    <Policies>
      <DefaultRunAsPolicy UserRef="LocalAdmin" />
    </Policies>
    

    Either of these seems to make it work. The best part is all it eventually did is create an empty npm folder there.