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.