When trying to export a document containing InlineUIContainer inside a read-only range, the XamlWriter.Save() method that is used in XamlFormatProvider.Serialize() throws StackOverflow exception. Sample code to reproduce the exception: InlineUIContainer container = new InlineUIContainer(); Button btn = new Button(); btn.Content = "Sample Button"; btn.Width = 70; btn.Height = 30; container.UiElement = btn; ReadOnlyRangeStart start = new ReadOnlyRangeStart(); ReadOnlyRangeEnd end = new ReadOnlyRangeEnd(); end.PairWithStart(start); this.rtb.InsertInline(container); this.rtb.Document.Selection.SelectAll(); this.rtb.InsertAnnotationRange(start, end); XamlFormatProvider provider = new XamlFormatProvider(); string content = provider.Export(this.rtb.Document); File.WriteAllText(@"c:\temp\asd.xaml", content);