title: Using an assembly for scripting in a referenced XSL template
body: <p>There are two XSL files. One includes another using an <code>&lt;xsl:include&gt;</code>. The main template decides which actual templates to call depending on node values, and included templates contain actual transformation rules. Nothing special here.</p>
  
  <p>But included file has a script block:</p>
  
  <pre><code>  &lt;msxsl:script language="VB" implements-prefix="user"&gt;
      &lt;msxsl:assembly href="C:\Absolute\Path\MyEscaper.dll" /&gt;
      &lt;msxsl:using namespace="ZebraEscaper.MyCompany" /&gt;
      &lt;![CDATA[
      Public Function escape(s As String) As String
        Return EncodeField(s, True)
      End Function
      ]]&gt;
    &lt;/msxsl:script&gt;
  </code></pre>
  
  <p>The user:escape() function is later used in the included template.</p>
  
  <p>Now, I go to VS2008 XSLT debugger.</p>
  
  <p>The main template calls <code>&lt;xsl:apply-templates&gt;</code> and the included template executes. And a FileNotFound exception occurs, "Could not load file or assembly 'MyEscaper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."</p>
  
  <p>Now, if I go to just the included file and execute it as if it was a standalone template, not included into anything, everything works. The assembly gets found and the function gets called, but obviously results don't make sense as the template designed to be an inclusion.</p>
  
  <p>So the question -- why can't the system find the assembly when the template is included?</p>
  
  <p><strong>More information</strong></p>
  
  <p>Documentation states that "The assembly path name is resolved twice - once during compilation and once during execution." If I intentionally make a typo in the path, I get same FileNotFound exception, but formatted differently, where the system says it cannot find <strong>file://C:\Absolute\Path\MyEscaper.dll</strong>. However, when the path is correct, the exception claims it couldn't find <strong>MyEscaper.dll, version=blabla, public token=null</strong>, and that exception occurs in CompiledStylesheet.dll created by .Net. I believe that the compiled stylesheet is told to call the assembly by name, not by href, and since it's not in its temporary folder, the call fails.</p>
  
  <p>Why so? Where and why does an absolute path get translated (wrongly) into a relative one, and how do I control it?</p>