MergeCommand throws InvalidOperationException merging pages with unpositioned outlines
Problem to Solve
System.InvalidOperationException
Message: 序列不包含任何元素
Source: System.Core
StackTrace: 在 System.Linq.Enumerable.Max(IEnumerable`1 source)
在 River.OneMoreAddIn.Commands.MergeCommand.<AppendOutlines>d__8.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在 River.OneMoreAddIn.Commands.MergeCommand.<Execute>d__5.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 River.OneMoreAddIn.Commands.MergeCommand.<Execute>d__5.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在 River.OneMoreAddIn.CommandFactory.<Run>d__11.MoveNext()
TargetSite: [System.Core] System.Linq.Enumerable.Max()
Root cause
MergeCommand.AppendOutlines assumes every outline on the target page has a <one:Position> element with a z attribute, and calls .Attributes("z").Max(...) unconditionally. OneNote outlines that have never been manually repositioned have no <Position> element at all, so the sequence is empty and Max() throws. The analogous Min() call used to compute topOffset from the child page's outlines has the same bug and can fail the same way.
MergeCommand throws InvalidOperationException merging pages with unpositioned outlines
Problem to Solve
Root cause
MergeCommand.AppendOutlinesassumes every outline on the target page has a<one:Position>element with azattribute, and calls.Attributes("z").Max(...)unconditionally. OneNote outlines that have never been manually repositioned have no<Position>element at all, so the sequence is empty andMax()throws. The analogousMin()call used to computetopOffsetfrom the child page's outlines has the same bug and can fail the same way.