What is the XslTransformException assembly in?

I have code that throws an XslTransformException. This is the desired behavior (XSL contains the xsl: message message element with the @terminate parameter set to yes).

I try to catch this exception in my code, but I cannot find the assembly containing this exception class, and I can not find any documentation for this exception in MSDN to get an idea of ​​a suitable inherited class (i.e. to avoid using the Exception class in my catch block).

I have references to System.Xml and Sytem.Xml.Linq that are referenced and have the following operators:

using System.Xml; using System.Xml.Xsl; 

An exception is the System.Xml.Xsl namespace; i.e:.

 System.Xml.Xsl.XslTransformException 

Any idea which assembly I need to use?

EDIT: As requested, please find a sample code to reproduce this exception:

 using System; using System.Xml; using System.Xml.Xsl; using System.Text; namespace StackOverflowDemo { class Program { static void Main(string[] args) { XmlDocument xmsl = new XmlDocument(); xmsl.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" exclude-result-prefixes=\"msxsl\"><xsl:output method=\"xml\" indent=\"yes\"/><xsl:template match=\"@* | node()\"><xsl:message terminate=\"yes\">this should throw an exception</xsl:message><xsl:copy><xsl:apply-templates select=\"@* | node()\"/></xsl:copy></xsl:template></xsl:stylesheet>"); XslCompiledTransform xsl = new XslCompiledTransform(); xsl.Load(xmsl.CreateNavigator()); XmlDocument xml = new XmlDocument(); xml.LoadXml("<root />"); StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb); /* try { */ xsl.Transform(xml.CreateNavigator(), writer); /* } catch(XslTransformException e) //<-- this class does not exist { Console.WriteLine(e.ToString()); } */ } } } 
+4
source share
3 answers

Adding the following catch shows everything:

 catch (Exception e) { var t = e.GetType(); while (t != null) { Console.WriteLine(t.AssemblyQualifiedName); t = t.BaseType; } } 

Output:

 System.Xml.Xsl.XslTransformException, System.Data.SqlXml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Xml.Xsl.XsltException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.SystemException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 

I would ignore the XslTransformException , though - you should catch an XsltException . In the end, this is what XslCompiledTransform.Transform documented for throwing.

+5
source

In System.Data.SqlXml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The exception is internal , although you cannot catch it directly. It extends XsltException , as John Skeet was mentioned, just catch an XsltException .

+3
source

Until I see a link to an XslTransformException in the namespace, the rest of System.Xsl lives on System.Xml.dll - you can see it on MSDN (as an example, I selected the first type in the namespace) on the line Assembly:, just above the syntax block.

0
source

Source: https://habr.com/ru/post/1444417/


All Articles