StockSharp/StockSharp · error · ArgumentNullException

Value cannot be null. (Parameter 'host')

Error message

Value cannot be null. (Parameter 'host')

What it means

Thrown by the SubscriptionRegistry constructor when the host argument (IStrategyHost) is null. SubscriptionRegistry is the internal component that manages subscribe/unsubscribe tracking and rule suspension for a strategy; it requires a host to obtain the strategy ID and generate transaction IDs. A null host would cause NullReferenceException on the first subscribe, so the primary constructor parameter is guarded.

Source

Thrown at Algo.Strategies/SubscriptionRegistry.cs:15

namespace StockSharp.Algo.Strategies;

/// <summary>
/// Subscription tracking. Manages subscribe/unsubscribe, suspend/resume for rules.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="SubscriptionRegistry"/>.
/// </remarks>
/// <param name="host">Strategy host.</param>
public class SubscriptionRegistry(IStrategyHost host)
{
	private readonly CachedSynchronizedDictionary<Subscription, bool> _subscriptions = [];
	private readonly SynchronizedDictionary<long, Subscription> _subscriptionsById = [];
	private readonly CachedSynchronizedSet<Subscription> _suspendSubscriptions = [];
	private readonly IStrategyHost _host = host ?? throw new ArgumentNullException(nameof(host));
	private int _rulesSuspendCount;

	/// <summary>
	/// Whether rules are currently suspended.
	/// </summary>
	public bool IsRulesSuspended => _rulesSuspendCount > 0;

	/// <summary>
	/// All tracked subscriptions.
	/// </summary>
	public IEnumerable<Subscription> Subscriptions => _subscriptions.CachedKeys;

	/// <summary>
	/// Fires when a subscription should be sent to connector.
	/// </summary>
	public event Action<Subscription> SubscriptionRequested;

	/// <summary>

View on GitHub (pinned to 601a191de6)

Solutions

  1. Provide a valid IStrategyHost (or a mock implementing IStrategyHost) when constructing SubscriptionRegistry.
  2. In test code, create a minimal mock IStrategyHost that provides StrategyId and GetNextTransactionId.
  3. Do not construct SubscriptionRegistry directly — let the Strategy class wire it up internally.
  4. If the host is conditionally available, defer construction until the host is set.

Example fix

// before (test code)
var registry = new SubscriptionRegistry(null);

// after
var mockHost = new MockStrategyHost { StrategyId = "test" };
var registry = new SubscriptionRegistry(mockHost);
Defensive patterns

Strategy: validation

Validate before calling

// In test code, always provide a mock host
var mockHost = new MockStrategyHost { StrategyId = "test", TransactionIdProvider = ... };
var registry = new SubscriptionRegistry(mockHost);

Prevention

When it happens

Trigger: Constructing new SubscriptionRegistry(null). This is typically internal infrastructure — it happens if the Strategy class is constructed in a way that passes a null host, or in test code that instantiates SubscriptionRegistry directly without a host.

Common situations: Unit test code that creates a SubscriptionRegistry in isolation without providing a mock IStrategyHost. Also occurs if a Strategy subclass overrides construction in a way that loses the host reference, or during partial/advanced initialization scenarios.

Related errors


AI-assisted analysis of StockSharp/StockSharp@601a191de6 (2026-08-13). Data as JSON: /api/errors/fbc400396859732a. Report an issue: GitHub.