Table of Contents

ISB005 Configure RpcTargetMetadata on creation

When creating a ServiceJsonRpcPolyTypeDescriptor, call WithRpcTargetMetadata(params ImmutableArray<RpcTargetMetadata>) somewhere in the overall expression that creates the descriptor.

If RpcTargetMetadata is left unset and the descriptor is later used on the service side to attach RPC to a target object, activation fails at runtime.

Examples of patterns that are flagged by this analyzer

The following code generates a diagnostic.

static readonly ServiceRpcDescriptor Descriptor = new ServiceJsonRpcPolyTypeDescriptor(
	new ServiceMoniker("name", new Version(1, 0)),
	ServiceJsonRpcPolyTypeDescriptor.Formatters.NerdbankMessagePack,
	ServiceJsonRpcPolyTypeDescriptor.MessageDelimiters.BigEndianInt32LengthHeader,
	PolyType.SourceGenerator.TypeShapeProvider_Microsoft_ServiceHub_Framework.Default);

Solution

Call WithRpcTargetMetadata somewhere in the overall expression that creates the descriptor.

static readonly ServiceRpcDescriptor Descriptor = new ServiceJsonRpcPolyTypeDescriptor(
	new ServiceMoniker("name", new Version(1, 0)),
	ServiceJsonRpcPolyTypeDescriptor.Formatters.NerdbankMessagePack,
	ServiceJsonRpcPolyTypeDescriptor.MessageDelimiters.BigEndianInt32LengthHeader,
	PolyType.SourceGenerator.TypeShapeProvider_Microsoft_ServiceHub_Framework.Default)
	.WithRpcTargetMetadata(RpcTargetMetadata.FromShape<IFoo>());