@@ -85,9 +85,12 @@ internal void LoadFromPart(OpenXmlPart openXmlPart)
8585 throw new ArgumentNullException ( nameof ( openXmlPart ) ) ;
8686 }
8787
88+ // Accessed before stream as it may cause the stream to reload
89+ var strictRelationshipFound = openXmlPart . OpenXmlPackage . StrictRelationshipFound ;
90+
8891 using ( Stream partStream = openXmlPart . GetStream ( FileMode . Open ) )
8992 {
90- LoadFromPart ( openXmlPart , partStream ) ;
93+ LoadFromPart ( openXmlPart , partStream , strictRelationshipFound ) ;
9194 }
9295 }
9396
@@ -96,12 +99,13 @@ internal void LoadFromPart(OpenXmlPart openXmlPart)
9699 /// </summary>
97100 /// <param name="openXmlPart">The part this root element to be loaded from.</param>
98101 /// <param name="partStream">The stream of the part.</param>
102+ /// <param name="strictRelationshipFound">Whether a strict relationship was found.</param>
99103 /// <returns>
100104 /// Returns true when the part stream is loaded successfully into this root element.
101105 /// Returns false when the part stream does not contain any xml element.
102106 /// </returns>
103107 /// <exception cref="InvalidDataException">Thrown when the part stream contains an incorrect root element.</exception>
104- internal bool LoadFromPart ( OpenXmlPart openXmlPart , Stream partStream )
108+ internal bool LoadFromPart ( OpenXmlPart openXmlPart , Stream partStream , bool strictRelationshipFound )
105109 {
106110 if ( partStream . Length < 4 )
107111 {
@@ -123,7 +127,7 @@ internal bool LoadFromPart(OpenXmlPart openXmlPart, Stream partStream)
123127 context . XmlReaderSettings . DtdProcessing = DtdProcessing . Prohibit ; // set to prohibit explicitly for security fix
124128#endif
125129
126- using ( var xmlReader = XmlConvertingReaderFactory . Create ( partStream , Features . GetNamespaceResolver ( ) , context . XmlReaderSettings , openXmlPart . OpenXmlPackage . StrictRelationshipFound ) )
130+ using ( var xmlReader = XmlConvertingReaderFactory . Create ( partStream , Features . GetNamespaceResolver ( ) , context . XmlReaderSettings , strictRelationshipFound ) )
127131 {
128132 context . MCSettings = openXmlPart . MCSettings ;
129133
0 commit comments