This is a very irritating bug/behaviour in Visual Studio. I am hoping that someone can tell me how to fix it or what we are doing wrong.
The scenario is that we have a program that runs some XSLT over some XML (see code below). There is nothing particularly strange about the code as far as I can tell. This code is run on a new Thread - that's about the only odd thing about it.
Now when we try and set a breakpoint in MyXslt.xsl
the breakpoints don't go red and we get the tooltip "The breakpoint will not currently be hit. No symbols have been loaded for the document" and we don't hit the breakpoint whilst debugging (the XSLT is definitely run).
There is a workaround: if we create a new "entry" XSLT to an empty tranform that just includes MyXslt.xsl
(let's call this entry.xsl
) like so
<?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:include href="MyXslt.xsl" />
</xsl:stylesheet>
then we can hit breakpoints in MyXslt.xsl
(any breakpoints in entry.xsl
suffer from the original problem).
Any ideas anyone??
Thanks in advance.
Here is some example code
var reportTransform = new XslCompiledTransform(true);
// load in the XSLT
using (var stream = File.OpenRead("MyXslt.xsl"))
{
var settings = new XsltSettings(true, true);
var streamReader = new StreamReader(stream);
string xml = streamReader.ReadToEnd();
var xsltDoc = new XmlDocument();
xsltDoc.LoadXml(xml);
XPathNavigator sourceNavigator = xsltDoc.CreateNavigator();
reportTransform.Load(sourceNavigator, settings, new XmlUrlResolver());
}
// Create input XML
var serializer = new XmlSerializer(typeof(MyObjectGraph));
MyObjectGraph objectGraph = GetInputData();
Stream input = XmlSerialisation.SerialiseToMemory(objectGraph, serializer);
XmlReader inputXmlReader = XmlReader.Create(input);
var output = new StringWriter();
var InternalWriterSettings = new XmlWriterSettings {CheckCharacters = false, Indent = false};
XmlWriter xmlReportWriter = XmlWriter.Create(output, InternalWriterSettings);
var args = new XsltArgumentList();
try
{
reportTransform.Transform(inputXmlReader, args, xmlReportWriter); // here is the interesting part
}
catch (Exception e)
{
Logging.Error(typeof(XsltHelper), "Error transforming report", e);
throw new XslTransformFailureFault("Error transforming report: " + e.Message);
}