I have some code which is throwing an XslTransformException. This is the desired behavior (the XSL contains an xsl:message element with @terminate set to yes).
I'm trying to catch this exception in my code, but can't find the assembly containing this exception's class, and can't find any documentation on this exception in MSDN to get an idea of a suitable inherited class (i.e. to avoid using the class Exception in my catch block).
I've got the System.Xml and Sytem.Xml.Linq assemblies referenced and have the following using statements:
using System.Xml;
using System.Xml.Xsl;
The exception is in the System.Xml.Xsl namespace; i.e.:
System.Xml.Xsl.XslTransformException
Any idea which assembly I need to reference?
EDIT: As requested, please find below 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());
}
*/
}
}
}
try{...} catch()
. – Mckayusing
statement so that just the exception name could be used in the code. – Mckay