Wednesday, May 30, 2012

Default parameter specifiers are not permitted

   
Context:

Windows XP
Visual Studio 2010
.NET 2.0

Problem:

I have this code:

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(reportXslFilename, XsltSettings.TrustedXslt, null);

 
When I ran it in .NET 4.0, it worked fine.  When I switched my project to .NET 2.0, I started getting this error:

System.Xml.Xsl.XslLoadException {"Default parameter specifiers are not permitted"}

Stack trace:
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at System.Xml.Xsl.XslCompiledTransform.Load(String stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)

...

Solution:

Since the error occurred at xslt.Load(reportXslFilename, XsltSettings.TrustedXslt, null), I thought it was something here.  Well, it turned out that it was something in my XSL.

I had script and something like this:

public string SayHello(string name = "World") { 
  return "Hello " + name; 
}

As you can see here, I have the default value for the parameter "name."

Removing this fixed my problem.  

Thursday, May 24, 2012

Green File Names In Windows

Context:

Windows Server 2008


Problem:

Green file names, resulting in files not readable by program.

Solution:

To make it not green anymore, right-click on the file, choose properties, then Advanced and uncheck "Encrypt contents to secure data"

Wednesday, May 23, 2012

XSLT Loop Over a Comma Delimited String

Context:

XSLT 1.0
XPath 1.0

Problem:

I needed to loop over a comma delimited string to work individually with each value in the string.

Solution:

Here's the sample string:  1,2,3,4,        

<xsl:call-template name="SimpleStringLoop">
    <xsl:with-param name="input" select="'1,2,3,4,'"/>
</xsl:call-template>

<xsl:template name="SimpleStringLoop">
    <xsl:param name="input"/>
    <xsl:if test="string-length($input) &gt; 0">
      <xsl:variable name="v" select="substring-before($input, ',')"/>
      <xsl:value-of select="$v"/>
      <xsl:call-template name="SimpleStringLoop">
        <xsl:with-param name="input" select="substring-after($input, ',')"/>
      </xsl:call-template>
    </xsl:if> 

</xsl:template>

Friday, May 18, 2012

C# MissingMethodException at runtime but compiles fine

Problem:

I got this MissingMethodException when I ran the code even though it compiled fine in Visual Studio.  I browsed the assembly referenced from the project, and the method that I wanted to call was there.  I was puzzled.  Since I'm new to .NET and don't know too much about it, it frustrated me for a bit on why that was happening.

Solution:

Well, it turned out that I had the same dll in GAC.  When I updated the dll in GAC, it ran fine.

Thursday, May 17, 2012

gacutil.exe is not a valid Win32 application

Context:

Windows XP

Problem:

C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\gacutil.exe was fine before until today when it suddenly threw me this error saying that it's not a valid Win32 application.

Solution:

It turned out that the error was caused by some recent Windows updates/installs.  When I restored my system to a prior point, it started working again.

Wednesday, April 11, 2012

Reference A User-Defined Assembly in XSL Stylesheet For Extension/Scripting in C#

Context:

Windows XP
C#
Visual Studio 2010
XSL stylesheet

Problem:

I need to reference my own assembly (dll) in XSL stylesheet.  I use  <msxsl:assembly href="C:\my.dll"/>, but I gives me an error and doesn't work. 

Solution:

I need to add my.dll to GAC (Global Assembly Cache) and reference it the XSL with <msxsl:assembly name="MyDLL"/>

To add it to GAC, I need to use the gacutil.exe, but before I do that, I have to sign my dll.  In VS 2010, I open up my project and open up properties.  Under the "Signing" tab, I check the box "Sign the assembly" and I "Choose a strong name key file."  I create a <New> key and rebuild my project and dll.  After that, install it to GAC by running gacutil.exe /i My.dll.  I get the success message "Assembly successfully added to the cache."  That's it.  Now, I can simply reference it by name.

I can check it by running gacutil.exe /l My.dll.  It returns "My, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7814e2fbc22d6551, processorArchitecture=MSIL"

If using the name alone in your XSL doesn't work, you can use this whole name above.