{"record":{"id":"74f04cbe5d79c1f0","repo":"QuantConnect/Lean","slug":"activesecurities-count-tostring-tocamelcase","errorCode":null,"errorMessage":"{ActiveSecurities.Count.ToString().ToCamelCase()} data points were expected, but only {slice.Count} were received","messagePattern":"(.+?) data points were expected, but only (.+?) were received","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/CustomDataWorksWithDifferentExchangesRegressionAlgorithm.cs","lineNumber":56,"sourceCode":"                throw new RegressionTestException($\"The time zone of security {firstCustomSecurity} should be {TimeZones.Utc}, but it was {firstCustomSecurity.Exchange.TimeZone}\");\n            }\n\n            var market2 = AddForex(\"EURUSD\", Resolution.Hour, Market.Oanda);\n            var secondCustomSecurity = AddData<ExampleCustomData>(market2.Symbol, Resolution.Hour, TimeZones.Utc, false);\n            if (secondCustomSecurity.Exchange.TimeZone != TimeZones.Utc)\n            {\n                throw new RegressionTestException($\"The time zone of security {secondCustomSecurity} should be {TimeZones.Utc}, but it was {secondCustomSecurity.Exchange.TimeZone}\");\n            }\n            _noDataPointsReceived = true;\n        }\n\n\n        public override void OnData(Slice slice)\n        {\n            _noDataPointsReceived = false;\n            if (slice.Count != ActiveSecurities.Count)\n            {\n                throw new RegressionTestException($\"{ActiveSecurities.Count.ToString().ToCamelCase()} data points were expected, but only {slice.Count} were received\");\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (_noDataPointsReceived)\n            {\n                throw new RegressionTestException($\"No points were received\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public bool CanRunLocally { get; } = true;\n\n        /// <summary>\n        /// This is used by the regression test system to indicate which languages this algorithm is written in.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomDataWorksWithDifferentExchangesRegressionAlgorithm.cs#L38-L74","documentation":"Asserts that every time slice carries exactly one data point per active security (slice.Count == ActiveSecurities.Count). With two forex + two custom-data securities, each aligned hourly slice should contain a point for each. A smaller slice.Count means a subscription dropped or mis-aligned a point on that bar.","triggerScenarios":"Stepping OnData on an hour boundary and finding slice.Count less than the number of active securities; one or more subscriptions did not emit a bar for that time.","commonSituations":"Custom-data source has gaps or its time-zone conversion shifts points into an adjacent bar; fillForward disabled so missing bars stay empty; or data-feed scheduling misaligns custom and forex feeds. Also happens if a security is added but its data file is empty for the range.","solutions":["Enable fillForward on the custom-data subscriptions so empty bars are filled to match forex.","Confirm the custom data Reader returns points stamped with the correct time-zone-converted time so they land in the right hourly bucket.","Check the custom data source for missing rows in the test window and either supply complete data or allow gaps.","Verify ActiveSecurities does not include a security whose data feed never starts (e.g., a stale AddData call)."],"exampleFix":"// before: fillForward=false causes uneven slice counts\nvar s = AddData<ExampleCustomData>(m.Symbol, Resolution.Hour, TimeZones.Utc, false);\n\n// after: fill forward so each bar has a point per security\nvar s = AddData<ExampleCustomData>(m.Symbol, Resolution.Hour, TimeZones.Utc, true);","handlingStrategy":"validation","validationCode":"// Validate per-slice coverage before acting\nif (slice.Count != ActiveSecurities.Count)\n{\n    var missing = ActiveSecurities.Keys.Except(slice.Keys).ToList();\n    Log($\"Slice missing {missing.Count} securities at {Time}: {string.Join(\",\", missing)}\");\n    return;\n}","typeGuard":"bool SliceIsComplete(Slice slice, int active) => slice.Count == active;","tryCatchPattern":null,"preventionTips":["Enable fillForward on subscriptions that must align bar-to-bar.","Stamp custom-data points with the correct time-zone-converted time so they bucket together.","When gaps are acceptable, handle them explicitly instead of asserting equality."],"tags":["regression-test","data-alignment","fill-forward","custom-data"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}