Moving your service fabric services to .Net core 3.1

Moving your service fabric services to .Net core 3.1

While I was working on SF Stateful and Stateless microservices which was on .Net framework 4.x, .Net Core 3.1 was released. After I upgraded all the Nuget Packages I started getting a runtime exception in the SF explorer for my service

Error - Error event: SourceId='System.Hosting', Property='Activation:1.0:1.0'. There was an error during activation. and There was an error during CodePackage activation.Container failed to start for image

First thing first ....checked our service fabric runtime version

Upgrade to MicrosoftServiceFabric.7.0.xxx.xxxx.exe (released 11/19) and the latest SDK.

Now you have two options for your service fabric cluster to run on .Net core either remove your cluster and create a new one like mentioned in the below steps.

or

Switch existing cluster node to use .Net core forcefully

Creating a new SF cluster and upgrading version

Uninstall Service Fabric

  1. Make a zip back up of C:\Program Files\Microsoft Service Fabric
  2. Consider creating a system restore point
  3. Open Add/remove
  4. Uninstall the Service Fabric SDK (for developers)
  5. Uninstall the Service Fabric Runtime
  6. If it doesn’t uninstall Uninstall SF Runtime issues below

Install Service Fabric - Developers

  1. Install the Web Platform Installer
  2. Start the Web Platform Installer
  3. Find Service Fabric
  4. Install the 4.0.457 version of the SDK (or latest)
  5. This will install the runtime as well

Install Service Fabric - Servers

  1. Download this version (or find the latest one) https://download.microsoft.com/download/5/e/e/5ee43eba-5c87-4d11-8a7c-bb26fd162b29/MicrosoftServiceFabric.7.0.457.9590.exe
  2. In an administrator PS window, run .\MicrosoftServiceFabric.7.0.457.9590.exe

You may have to set the correct server certificate thumbprint and DNS URL name. With a PowerShell script similar to this.

Connect-ServiceFabricCluster -ConnectionEndpoint $ClusterEndpoint -KeepAliveIntervalInSec 10 -X509Credential -ServerCertThumbprint $Thumbprint -FindType FindByThumbprint -FindValue $Thumbprint -StoreLocation LocalMachine -StoreName Root
$currentSFVersion = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Service Fabric' -Name 'FabricVersion'

if($currentSFVersion.FabricVersion -ne $SFUpgradeVersion)
{
    Write-Host "Upgrading Service Fabric Cluster from Verison $($currentSFVersion.FabricVersion) to Version $SFUpgradeVersion"
    Start-ServiceFabricClusterUpgrade -Code -CodePackageVersion $SFUpgradeVersion -Monitored -FailureAction Rollback
}
else
{
    Write-Host "Current Service Fabric Version($($currentSFVersion.FabricVersion)) matches desired Version($SFUpgradeVersion)"
}

Verify the versions in add/remove programs. If you don’t have the Fabric manager running, Start Menu > Service Fabric Cluster Manager

Now create your cluster. When that is done, click Manage Local Cluster and check out the explorer in the browser

For devs:

  • Make sure Visual Studio can still build the SF solution
  • Deploy API locally to check it out

Note: C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code\NS_7 now exists and fixes the .Net Core 3.1 and newer packages problem.

Uninstall SF Runtime issues

I hope to add or remove programs works for you. If not, these steps should save you a few hours. This may have been caused when I tried to run the Web Platform installer before uninstalling. I clicked the cancel button after it ran without progress for a long time.

Don't forget to restart service in the cluster if you face any issue at this moment.

Switch existing cluster node to use .Net core forcefully

Right-click on the project of your service fabric service and choose ‘Unload Project.’ Then right-click again and choose Edit .csproj.

Now you’ll need to remove everything except for your project references and your package references and add this for the Service Fabric to work:

<PropertyGroup>

  <TargetFramework>netcoreapp3.1</TargetFramework>

  <PreserveCompilationContext>true</PreserveCompilationContext>

  <AssemblyName>Condeco.Connect.Fabric.TokenManager</AssemblyName>

  <OutputType>Exe</OutputType>

  <PackageId>Condeco.Connect.Fabric.TokenManager</PackageId>

  <Platforms>AnyCPU;x64</Platforms>

  <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>

  <ServerGarbageCollection>True</ServerGarbageCollection>

  <RuntimeIdentifier>win7-x64</RuntimeIdentifier>

  <TargetLatestRuntimePatch>False</TargetLatestRuntimePatch>

 </PropertyGroup>

Now save the csproj and reload the project.

Finally, remove the AssemblyInfo.cs file in your project and build it.

Assuming your nugets are all .net core compatible, it should now be building successfully and will also work on your Service Fabric cluster.

No alt text provided for this image


CHEERS

要查看或添加评论,请登录

Ajay Kumar??的更多文章

社区洞察

其他会员也浏览了