Contract and lifetime analysis
The Nerdbank.JsonRpc package includes C# analyzers and a client proxy source generator. Apply JsonRpcContractAttribute to an interface to identify it as an RPC contract. The same checks also apply to RpcMarshalableAttribute interfaces. The package also checks ownership of brokered-service proxies and cached rentals, independently of contract attributes.
| Rule | Default severity | Description |
|---|---|---|
| NBJSONRPC001 | Warning | Unsupported proxy input |
| NBJSONRPC002 | Warning | Colliding wire method names |
| NBJSONRPC003 | Warning | Unsupported contract member |
| NBJSONRPC004 | Warning | Dispose of brokered-service proxies |
| NBJSONRPC005 | Warning | Do not store service rentals in fields or properties |
| NBJSONRPC010 | Warning | Annotate RPC proxy interfaces |
| NBJSONRPC011 | Warning | Use supported interfaces for RPC proxies |
| NBJSONRPC050 | Warning | Use IClientProxy for marshalable interface checks |
By default, a contract also generates a client proxy.
Set JsonRpcContractAttribute.GenerateProxy to false to retain contract analysis without generating a proxy.
This also suppresses proxy generation when the interface has RpcMarshalableAttribute.
An interface without a generated proxy does not need to be partial unless its PolyType shape generation requires it.
[JsonRpcContract(GenerateProxy = false)]
[GenerateShape(IncludeMethods = MethodShapeFlags.PublicInstance)]
public partial interface ITargetOnly
{
ValueTask DisplayMessageAsync(string message, CancellationToken cancellationToken);
}
The former GenerateJsonRpcProxyAttribute has been replaced by JsonRpcContractAttribute.
Replace the attribute name; default proxy generation behavior is unchanged.