From 22138227ad0165ccc6928d361d79e40a83193a38 Mon Sep 17 00:00:00 2001 From: Thomas Taylor Date: Wed, 1 Apr 2020 14:05:25 -0400 Subject: [PATCH] Add null checks in SdtTagName SdtTagName was throwing lots of exceptions, so I downloaded your code and took a look in debug mode. The ".Element(W.tag)" part was null. I added null checks (via the question marks), and it solved my problem and seems to run quite a bit faster. I did not spend any time trying to understand your code, but if the try/catch is there just for handling nulls, maybe that is no longer needed. --- .../OpenXMLHelpers/XElementExtensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/TemplateEngine.Docx/OpenXMLHelpers/XElementExtensions.cs b/sources/TemplateEngine.Docx/OpenXMLHelpers/XElementExtensions.cs index ae83812..edf376b 100644 --- a/sources/TemplateEngine.Docx/OpenXMLHelpers/XElementExtensions.cs +++ b/sources/TemplateEngine.Docx/OpenXMLHelpers/XElementExtensions.cs @@ -127,10 +127,10 @@ public static string SdtTagName(this XElement sdt) try { - return sdt - .Element(W.sdtPr) - .Element(W.tag) - .Attribute(W.val) + return sdt? + .Element(W.sdtPr)? + .Element(W.tag)? + .Attribute(W.val)? .Value; } catch (Exception)