If you try to register an actor within a Service Fabric service like this:
ActorRuntime.RegisterActorAsync((serviceContext, agentType) => new AgentService(serviceContext, agentType)) .GetAwaiter() .GetResult();
but getting the following exception:
System.Fabric.FabricException: ‘Invalid Service Type’
Inner Exception: COMException: Exception from HRESULT: 0x80071C21
then in Event Log (Applications and Services Logs -> Microsoft-Service-Fabric -> Admin) you’ll see an entry like this:
StartRegister: HeartbeatActorServiceType is invalid and cannot be registered. Only ServiceTypes specified in the ServiceManifest can register.
This happens because by default service name is inferred from actor name, e.g. HeartbeatActor would produce HeartbeatActorServiceType. And your service is called differently, AgentService in my case. Hence the error.
To change the behavior, apply [ActorServiceAttribute]
to the actor:
[ActorService(Name = nameof(AgentService))] [StatePersistence(StatePersistence.None)] class HeartbeatActor : Actor, IHeartbeatActor { }
That’s it, folks!