views:

186

answers:

1

I'm using an XML-Document-Transform to transform my web.config file for deployment to a staging server. Unfortunately it isn't transforming exactly as specified and is adding some whitespace to an element's text. This whitespace is then being picked up by the Castle Windsor configuration that I use and bombing the application.

Here's an example:

web.config:

<configuration>
  <castle>
    <properties>
      <serverUrl>http://test&lt;/serverUrl&gt;
    <properties>
    <components>
      <component id="MyService">
        <parameters>
          <Url>#{serverUrl}/MyService.asmx</Url>
        </parameters>
      </component>
    </components>
  <castle>
<configuration>

web.staging.config:

<configuration>
  <castle>
    <properties>
      <serverUrl xdt:Transform="Replace">http://staging&lt;/serverUrl&gt;
    <properties>
  <castle>
<configuration>

Output web.config:

<configuration>
  <castle>
    <properties>
      <serverUrl>http://staging
      </serverUrl>
    <properties>
    <components>
      <component id="MyService">
        <parameters>
          <Url>#{serverUrl}/MyService.asmx</Url>
        </parameters>
      </component>
    </components>
  <castle>
<configuration>

As you can see additional whitespace has been inserted in to the serverUrl element by the transformation.

Unfortunately Castle includes the whitespace when inserting the serverUrl into the Url of the service which creates an invalid URL.

Anyone else come across this? Anyone got a solution that still uses the new Microsoft transformation method but doesn't cause additional whitespace to be inserted?

IMHO this is a bug in the transform process although Castle should probably be ignoring the whitespace too.

Many thanks, Rob

+1  A: 

This issue also affects applicationSettings, but I was able to work around it by trimming the white space as you suggested. Here's my Settings.cs file.

internal sealed partial class Settings
{
    public override object this[string propertyName]
    {
        get
        {
            // trim the value if it's a string
            string value = base[propertyName] as string;
            if (value != null)
            {
                return value.Trim();
            }

            return base[propertyName];
        }
        set { base[propertyName] = value; }
    }
}

I'm afraid this won't help your issue with Castle, but perhaps it will help someone else!

jrummell