{"record":{"id":"68205d962302c423","repo":"AvaloniaUI/Avalonia","slug":"cannot-call-measure-using-a-size-with-nan-values","errorCode":null,"errorMessage":"Cannot call Measure using a size with NaN values.","messagePattern":"Cannot call Measure using a size with NaN values\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Layout/Layoutable.cs","lineNumber":371,"sourceCode":"        /// </summary>\n        internal Rect? PreviousArrange => _previousArrange;\n\n        /// <summary>\n        /// Creates the visual children of the control, if necessary\n        /// </summary>\n        public virtual void ApplyTemplate()\n        {\n        }\n\n        /// <summary>\n        /// Carries out a measure of the control.\n        /// </summary>\n        /// <param name=\"availableSize\">The available size for the control.</param>\n        public void Measure(Size availableSize)\n        {\n            if (double.IsNaN(availableSize.Width) || double.IsNaN(availableSize.Height))\n            {\n                throw new InvalidOperationException(\"Cannot call Measure using a size with NaN values.\");\n            }\n\n            if (!IsMeasureValid || _previousMeasure != availableSize)\n            {\n                using var activity = Diagnostic.MeasuringLayoutable()?\n                    .AddTag(Diagnostic.Tags.Control, this);\n\n                var previousDesiredSize = DesiredSize;\n                var desiredSize = default(Size);\n\n                IsMeasureValid = true;\n\n                try\n                {\n                    _measuring = true;\n                    desiredSize = MeasureCore(availableSize);\n                }\n                finally","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Layout/Layoutable.cs#L353-L389","documentation":"Measure throws when either Width or Height of the supplied Size is NaN. Avalonia's layout contract treats NaN as 'unset/undefined' for layout slots and explicitly forbids passing it as available size, because NaN cannot be compared or used in measure math. Infinity is allowed (means 'unconstrained'), but NaN is always rejected.","triggerScenarios":"Calling control.Measure(availableSize) where availableSize.Width or availableSize.Height is double.NaN. Common when the size is sourced from an uninitialized property, an unset binding, or computed arithmetic that produced NaN (e.g. 0/0).","commonSituations":"Binding AvailableSize to a property that defaults to NaN. Computation like division by zero producing NaN before Measure. Passing DesiredSize (which can legitimately be NaN in edge states) back as available size. Custom layout panels computing available space incorrectly.","solutions":["Replace NaN dimensions with 0 or a concrete value, or use double.PositiveInfinity for unconstrained axes, before calling Measure.","Trace the source of the NaN — inspect bindings and computed sizes feeding into the Measure call.","In custom panels, sanitize availableSize: size = new Size(double.IsNaN(size.Width) ? 0 : size.Width, ...)."],"exampleFix":"// before\ncontrol.Measure(new Size(double.NaN, availableHeight));\n\n// after\nvar w = double.IsNaN(availableWidth) ? 0 : availableWidth;\ncontrol.Measure(new Size(w, availableHeight));","handlingStrategy":"validation","validationCode":"static Size Sanitize(Size s) => new Size(\n    double.IsNaN(s.Width) ? 0 : s.Width,\n    double.IsNaN(s.Height) ? 0 : s.Height);\n\ncontrol.Measure(Sanitize(availableSize));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In custom panels, sanitize availableSize before forwarding to child.Measure.","Never pass DesiredSize or computed values that could be NaN into Measure.","Treat NaN as a bug in upstream binding/computation and trace it."],"tags":["layout","measure","nan","custom-panel"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}