Geeks With Blogs
Matt deClercq

I ran across this issue today when working with a WCF service project. We had generated a settings file through the project properties and in turn added entries into the web.config transform files for the different deployment modes. The base config and the transform blocks for the <applicationSettings> element were what you would expect:

Web.config:

  <applicationSettings>
    <Namespace.Properties.Settings>
      <setting name="test" serializeAs="String">
        <value>test</value>
      </setting>
      <Namespace.Properties.Settings>
  </applicationSettings>

Web.Release.config:

  <applicationSettings>
    <Namespace.Properties.Settings xdt:Transform="Replace">
      <setting name="test" serializeAs="String">
        <value>test transform</value>
      </setting>
      <Namespace.Properties.Settings>
  </applicationSettings>  

However, when a deployment package or publish was called and the transforms occured we were experiencing runtime errors when the values were evaluated by the code. After inspecting the transformed Web.config I noticed that the <applicationSettings>block now had additional linebreaks and whitespace added to the <value> element causing the string values to resolve as invalid in the code.

Transformed Web.Config:

  <applicationSettings>
    <Namespace.Properties.Settings xdt:Transform="Replace">
      <setting name="test" serializeAs="String">
        <value>
          test transform
        </value>
      </setting>
      <Namespace.Properties.Settings>
  </applicationSettings>

Did some research and found the a discussion of the issue on Microsoft Connect. Seems as though there is a workaround involving an override addition to the Settings.cs file of the project that can be implemented while waiting for a HotFix. Or you could just call Trim() on every line where you use one of these values.

Good luck!

 

Posted on Thursday, October 21, 2010 11:20 AM | Back to top


Comments on this post: Web.config transforms on configs w/ Namespace.Properties.Settings blocks

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Matt deClercq | Powered by: GeeksWithBlogs.net