{"record":{"id":"fbc400396859732a","repo":"StockSharp/StockSharp","slug":"value-cannot-be-null-parameter-host","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'host')","messagePattern":"Value cannot be null\\. \\(Parameter 'host'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Algo.Strategies/SubscriptionRegistry.cs","lineNumber":15,"sourceCode":"namespace StockSharp.Algo.Strategies;\n\n/// <summary>\n/// Subscription tracking. Manages subscribe/unsubscribe, suspend/resume for rules.\n/// </summary>\n/// <remarks>\n/// Initializes a new instance of the <see cref=\"SubscriptionRegistry\"/>.\n/// </remarks>\n/// <param name=\"host\">Strategy host.</param>\npublic class SubscriptionRegistry(IStrategyHost host)\n{\n\tprivate readonly CachedSynchronizedDictionary<Subscription, bool> _subscriptions = [];\n\tprivate readonly SynchronizedDictionary<long, Subscription> _subscriptionsById = [];\n\tprivate readonly CachedSynchronizedSet<Subscription> _suspendSubscriptions = [];\n\tprivate readonly IStrategyHost _host = host ?? throw new ArgumentNullException(nameof(host));\n\tprivate int _rulesSuspendCount;\n\n\t/// <summary>\n\t/// Whether rules are currently suspended.\n\t/// </summary>\n\tpublic bool IsRulesSuspended => _rulesSuspendCount > 0;\n\n\t/// <summary>\n\t/// All tracked subscriptions.\n\t/// </summary>\n\tpublic IEnumerable<Subscription> Subscriptions => _subscriptions.CachedKeys;\n\n\t/// <summary>\n\t/// Fires when a subscription should be sent to connector.\n\t/// </summary>\n\tpublic event Action<Subscription> SubscriptionRequested;\n\n\t/// <summary>","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/StockSharp/StockSharp/blob/601a191de678bff83da28b14828f8885214ca71c/Algo.Strategies/SubscriptionRegistry.cs#L1-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide a valid IStrategyHost (or a mock implementing IStrategyHost) when constructing SubscriptionRegistry.","In test code, create a minimal mock IStrategyHost that provides StrategyId and GetNextTransactionId.","Do not construct SubscriptionRegistry directly — let the Strategy class wire it up internally.","If the host is conditionally available, defer construction until the host is set."],"exampleFix":"// before (test code)\nvar registry = new SubscriptionRegistry(null);\n\n// after\nvar mockHost = new MockStrategyHost { StrategyId = \"test\" };\nvar registry = new SubscriptionRegistry(mockHost);","handlingStrategy":"validation","validationCode":"// In test code, always provide a mock host\nvar mockHost = new MockStrategyHost { StrategyId = \"test\", TransactionIdProvider = ... };\nvar registry = new SubscriptionRegistry(mockHost);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never construct SubscriptionRegistry with a null host.","Provide a mock IStrategyHost in unit tests.","Let the Strategy class wire up its own SubscriptionRegistry internally."],"tags":["subscription","null-argument","infrastructure","constructor","argument-validation"],"backgroundTag":null,"analyzedSha":"601a191de678bff83da28b14828f8885214ca71c","analyzedAt":"2026-08-13T20:43:24.460Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}