For example:
Rather than:
xslTrans.Transform(xpn, Nothing, sw)
I would write:
xslTrans.Transform(xpn, Nothing, sw, Nothing)
And voila! it works just fine.
The next failed piece of upgraded code was this
xslTrans.Load(New XmlNodeReader(xsl))
In this case you need to add two more parameters, an 'XMLResolver' and an 'evidence' param. This worked:
xslTrans.Load(New XmlNodeReader(xsl),Nothing, Nothing)
Evil Moral of the story is:
If a parameter is required, but you don't know why, just set it to 'nothing.'
That's not the sort of lesson I'd like to teach people. But it's what Microsoft taught me today.
Third situation was a bit trickier and called for an even nastier hack.
This worked in version 1.0, but threw a warning in 1.1:
xsltransform.Transform(xmlDoc.CreateNavigator, Nothing)
The warning was a familiar one:
Public Function Transform(input As System.Xml.XPath.XPathNavigator, args As System.Xml.Xsl.XsltArgumentList) As System.Xml.XmlReader' is obsolete: 'You should pass XmlResolver to Transform() method'
My first thought was: 'add a new parameter, value of nothing'. But this failed because the compiler couldn't resolve which overloaded interface I was after. The result of such an approach was:
Overload resolution failed because no accessible 'Transform' is most specific for these arguments:
'Public Sub Transform(input As System.Xml.XPath.XPathNavigator, args As System.Xml.Xsl.XsltArgumentList, output As System.IO.TextWriter)': Not most specific.
'Public Sub Transform(input As System.Xml.XPath.XPathNavigator, args As System.Xml.Xsl.XsltArgumentList, output As System.IO.Stream)': Not most specific.
'Public Sub Transform(input As System.Xml.XPath.XPathNavigator, args As System.Xml.Xsl.XsltArgumentList, output As System.Xml.XmlWriter)': Not most specific.
'Public Function Transform(input As System.Xml.XPath.XPathNavigator, args As System.Xml.Xsl.XsltArgumentList, resolver As System.Xml.XmlResolver) As System.Xml.XmlReader': Not most specific.
i.e., 'Sure you want nothing -- but what type of nothing??' Fair cop, so I tried this instead:
Dim reader As XmlReader = xsltransform.Transform(xmlDoc.CreateNavigator, Nothing, New XmlUrlResolver)
Now there were no warnings and it did compile. But did it work? Who cares? Because right then i thought of a cleverer and nastier solution, that would be bound to confuse other developers. Naturally, I gravitated toward it immediately:
Dim reader As XmlReader = xsltransform.Transform(xmlDoc.CreateNavigator, args:=Nothing, resolver:=Nothing)
I didn't test that it worked, because 'hey, it should, right?'
At that moment, another, nastier solution occurred to me. I call this one: "What type of 'nothing'? **This** type of nothing!"
Dim reader As XmlReader = xsltransform.Transform(xmlDoc.CreateNavigator, Nothing, CType(Nothing, XmlResolver))
No time to test it, but the compiler doesn't freak, so my money says she works.
And now I can get on with writing other, better, faster bugs.
As an old friend said to me just yesterday: "One man's bug is another man's paycheck."