Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code is missing for service MyServicePkg

I am attempting to upgrade my application like so:

enter image description here

It fails with the following error:

enter image description here

Error details:

2>Test-ServiceFabricApplicationPackage : The BuildLayout of the application in
2>C:\Users\me\AppData\Local\Temp\TestApplicationPackage_2205895293421\4myc2vpp.bdq\Debug is invalid. Code is
2>missing for service MyServicePkg.
2>At C:\Program Files\Microsoft SDKs\Service
2>Fabric\Tools\PSModule\ServiceFabricSDK\Publish-UpgradedServiceFabricApplication.ps1:135 char:38
2>+ ... nSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse -Im ...
2>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2> + CategoryInfo : InvalidOperation: (:) [Test-ServiceFabricApplicationPackage], FabricImageBuilderValidati
2> onException
2> + FullyQualifiedErrorId : TestApplicationPackageErrorId,Microsoft.ServiceFabric.Powershell.TestApplicationPackage 2>
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:40.4035177
2>The PowerShell script failed to execute.
========== Build: 1 succeeded, 0 failed, 46 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

Here are my properties for that specific project:

enter image description here

What am I doing wrong? What does this exception mean?

like image 788
Alex Gordon Avatar asked Feb 13 '18 17:02

Alex Gordon


2 Answers

At a higher level, this error happens when the folder named "Code" is missing under the ServiceFabric Project Folder during Publish (after build shows as successfully completed).

Build is the culprit here, not Publish, as Publish is expected to look for assets under Folder Path: {{SFProjectFolder}}\pkg\Release\{{ServiceName}}

Please note that the {{ServiceName}} and "Code" is taken from the ServiceManifest.xml of the corresponding project referenced in the SF application.

ServiceManifest.xml

<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="{{ServiceName}}" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <ServiceTypes>
    <StatelessServiceType ServiceTypeName="{{ServiceType}}" />
  </ServiceTypes>
  <CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <ExeHost>
        <Program>{{ServiceName}}.exe</Program>
      </ExeHost>
    </EntryPoint>
  </CodePackage>
  <ConfigPackage
  • What caused the issue: From other answers, it looks like the Build not copying the compiled assets into the right path/folder, could happen due to multiple issues. In our case, we had changed the Configuration Manager settings for Release Configuration from AnyCPU to x64 and deleted the AnyCPU Platform setting from the solution. And for some reason, the Services.csproj still had the AnyCPU Platform setting. We ended up having the build showing as successful, but "Code" folder not being generated under Release folder.

  • Fix: To fix this, we had to manually edit the .csproj and remove the PropertyGroup sections that still used "AnyCPU" like the one below:
    PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "

After this change, Build correctly placed the contents in the right path and Publish worked as expected.

like image 29
Matt.G Avatar answered Sep 30 '22 08:09

Matt.G


I would go with Hans Passant's comment:

The most basic mishap is that the name you used in the ServiceManifest.xml file does not match the name of the .exe that your project generates

It is also visible in your debug output as the build succeeded but the publish failed.

========== Build: 1 succeeded, 0 failed, 46 up-to-date, 0 skipped ========== ========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

It can happen in a number of ways and most probably due to renaming of the project or renaming of the Assembly Name. If you rename the project or the Assembly Name of your project, your build executable will be according to that name. Consider the following case.

Application Properties

I renamed the Assembly Name from "MyService" to "MyRenamedService". So the build executable will be MyRenamedService.exe. So you have to set this in your ServiceManifest.xml.

<CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <ExeHost>
        <Program>MyRenamedService.exe</Program>
        <WorkingFolder>CodePackage</WorkingFolder>
      </ExeHost>
    </EntryPoint>
</CodePackage>

The best way to be sure of the build executable path is to build the solution. It will show the full path of the executable in Output window.

1>------ Build started: Project: Web1, Configuration: Debug Any CPU ------
1>Web1 -> C:\.....\Application2\Web1\bin\Debug\net461\win7-x64\MyRenamedService.exe
2>------ Build started: Project: Application2, Configuration: Debug x64 ------
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Here Web1 is the Project Name I started with, MyRenamedService.exe is the build executable name (because I renamed the Assembly Name), it should be set in the ServiceManifest.xml as shown above.

like image 53
Munim Munna Avatar answered Sep 30 '22 07:09

Munim Munna