Our virtual home

Strange XSL Transform Exception - figured out

Recently we migrated our software dev. to use CLR 2.0. One part of the migration was to rework the usage of XslTransform class to the new XslCompiledTransform class. Reading the "Migrating From the XslTransform class" MSDN paper, it was not much work, just minutes. But then I got this strange exception:

Cannot transform XML using stylesheet 'transform.xslt.'
Exception: Extension function parameters or return values which have Clr type 'ConcatString' are not supported.

This really took me a half day to track it down! First, I did the usual things like reading more carefully the MSDN docs (my wrong direction: security issues), google'd for it and found at least one topic about. This was the right direction to solve it, but I tried various other things to get around - inclusive a complete redesign of the transformation code not using any stylesheet scripts. At last I was more confused (introduced other errors) than as I started, so I reverted the most unrelated changes. After reading the more interesting post "Introducing XslCompiledTransform" and IM'ed with a OS project coworker it gets more clear to me what happens: the System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltResult(XmlQueryType xmlType, Object value) visible in the call stack try to make my functions to return strong types - but: only the top level functions called from XSL element! Here is the non-working stylesheet code sample:

    
    function fmtDate(val, fmtmask)
    {

  var s = "" + val; 
  ...
  return formatDate(new Date(s.substring(0,4),s.substring(4,6)-1,s.substring(6,8)), fmtmask);
    }
    function formatDate(varDate, bstrFormat)
    {
 ...
 return "" + formattedDate;
}
]]>

And this is the working one:

    
    function fmtDate(val, fmtmask)
    {

  var s = "" + val; 
  ...
  return "" + formatDate(new Date(s.substring(0,4),s.substring(4,6)-1,s.substring(6,8)), fmtmask);
    }
    function formatDate(varDate, bstrFormat)
    {
 ...
 return "" + formattedDate;
}
]]>

You notice the small but important difference? Now the stylesheet compiler consider my return value correctly as a string. Whoa...

 

» Similar Posts

  1. Remoting from CLR 1.1 to 2.0 and back: issue 1
  2. How to prevent the configuration file watcher thread in Microsoft Enterprise Library 3.1
  3. More to know about .NET Timers

» Comments

  • Hèctor Rubio avatar

    Thanks Torsten!I was having exactly the same issue... upgrading an app to clr 2.0 and facing the XSLT with inline javascript was no longer working.Best regards,Hèctor

    Hèctor Rubio — May 23, 2007 3:05 PM
  • Comments are closed