{"record":{"id":"a1c29bd5c2ee50ba","repo":"dotnet/wpf","slug":"sr-maximumnotesizeexceeded","errorCode":null,"errorMessage":"SR.MaximumNoteSizeExceeded","messagePattern":"SR\\.MaximumNoteSizeExceeded","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteContentControl.cs","lineNumber":211,"sourceCode":"            /// <summary>\n            /// Save the RichTextBox data to an Xml node\n            /// </summary>\n            /// <param name=\"node\"></param>\n            public override void Save(XmlNode node)\n            {\n                // make constant\n                Debug.Assert(node != null && !IsEmpty);\n                RichTextBox richTextBox = (RichTextBox)InnerControl;\n\n                TextRange rtbRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);\n                if (!rtbRange.IsEmpty)\n                {\n                    using (MemoryStream buffer = new MemoryStream())\n                    {\n                        rtbRange.Save(buffer, DataFormats.Xaml);\n\n                        if (buffer.Length.CompareTo(MaxBufferSize) > 0)\n                            throw new InvalidOperationException(SR.MaximumNoteSizeExceeded);\n\n                        // Using GetBuffer avoids making a copy of the buffer which isn't necessary\n                        // Safe cast because the array's length can never be greater than Int.MaxValue\n                        node.InnerText = Convert.ToBase64String(buffer.GetBuffer(), 0, (int)buffer.Length);\n                    }\n                }\n            }\n\n\n            /// <summary>\n            /// Load the RichTextBox data from an Xml node\n            /// </summary>\n            /// <param name=\"node\"></param>\n            public override void Load(XmlNode node)\n            {\n                Debug.Assert(node != null);\n                RichTextBox richTextBox = (RichTextBox)InnerControl;\n","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteContentControl.cs#L193-L229","documentation":"When saving a text StickyNote, the RichTextBox XAML range is serialized to a MemoryStream; if the serialized XAML exceeds MaxBufferSize, Save throws InvalidOperationException('MaximumNoteSizeExceeded'). WPF enforces this limit because StickyNote content is stored as base64 inside the annotation XML and unbounded notes would bloat the annotation store.","triggerScenarios":"Saving a text StickyNote whose content, when saved as XAML from the inner RichTextBox, is larger than MaxBufferSize (~several KB), e.g. pasting large text or many formatted runs into a sticky note.","commonSituations":"Pasting documents or large code snippets into a sticky note, notes with heavy inline formatting that inflate XAML size, annotation stores migrated from apps without the limit.","solutions":["Reduce the StickyNote content (remove pasted bulk text/formatting) before the note is committed.","Move large content out of the sticky note (store in a file/document) and keep only a short reference or summary in the note.","Pre-check content size: serialize the RichTextRange yourself and warn the user before Save is invoked.","Catch InvalidOperationException around save/commit (e.g. in response to losing focus or navigation) and surface a size warning instead of failing silently."],"exampleFix":"// before\nrtbRange.Save(buffer, DataFormats.Xaml); // may exceed MaxBufferSize\n// after\nrtbRange.Save(buffer, DataFormats.Xaml);\nif (buffer.Length.CompareTo(MaxBufferSize) > 0)\n{\n    buffer.SetLength(0);\n    rtbRange.Save(buffer, DataFormats.Text); // or trim content / warn user\n}","handlingStrategy":"try-catch","validationCode":"var buf = new MemoryStream(); rtbRange.Save(buf, DataFormats.Xaml);\nbool withinLimit = buf.Length <= MaxBufferSize;","typeGuard":null,"tryCatchPattern":"try { SaveNoteContent(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"size\")) { MessageBox.Show(\"Sticky note content too large; reduce it.\"); }","preventionTips":["Keep sticky notes short; store bulk text in the document, not the note.","Hook the save/commit path and warn users before exceeding the cap.","Avoid pasting large formatted blocks into StickyNote controls."],"tags":["wpf","stickynote","size-limit"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}