Closed itsamaik closed 1 year ago
Do you need an example to replicate this? In that case I can try to distill my document and make an example.
Does this commit fix the issue?
https://github.com/antonmihaylov/OpenXmlTemplates/commit/ee923de6cbb9540999f62fbdd333edbe400fc44e
When the following conditions are met:
The following error occurs: System.InvalidOperationException: 'The parent of this element is null.'
at DocumentFormat.OpenXml.OpenXmlElement.Remove() at OpenXMLTemplates.Documents.ContentControl.Remove() at OpenXMLTemplates.ControlReplacers.ConditionalRemoveControlReplacer.ProcessControl(String variableIdentifier, IVariableSource variableSource, ContentControl contentControl, List1 otherParameters) at OpenXMLTemplates.ControlReplacers.ControlReplacer.Replace(ContentControl control, IVariableSource variableSource) at OpenXMLTemplates.ControlReplacers.ControlReplacer.Replace(ControlReplacementExecutionData sdtElement) at OpenXMLTemplates.ControlReplacers.ControlReplacer.ExecuteQueue() at OpenXMLTemplates.Engine.OpenXmlTemplateEngine.ReplaceAll(TemplateDocument doc, IVariableSource variableSource) at Portal.Actions.DataCollectionAction.CreateWordDoc(String filepath, Account account) in D:\_Dev\Portal\Actions\DataCollectionAction.cs:line 161 at Portal.Actions.DataCollectionAction.<WriteDocsAsync>d__6.MoveNext() in D:\_Dev\Portal\Actions\DataCollectionAction.cs:line 142 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Portal.Actions.DataCollectionAction.<RunAsync>d__5.MoveNext() in D:\_Dev\Portal\Actions\DataCollectionAction.cs:line 40 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Portal.App.<Run>d__4.MoveNext() in D:\_Dev\Portal\App.cs:line 31 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Portal.Program.<MainAsync>d__1.MoveNext() in D:\_Dev\Portal\Program.cs:line 34 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Portal.Program.Main(String[] args) in D:\_Dev\Portal\Program.cs:line 21
So with a false (bool) value inside of a repeating control (rich text content control).
I have tried to look through the code but could not find a reason why the ContentControl suddenly does not have a parent according to DocumentFormat.OpenXml.OpenXmlElement.Remove(). When using _not I am able to hide/show it using the boolean. However when not using the parameter it suddenly fails at removing the control. I am suspecting it has something to do with getting the variable, but I'm not sure.