Issues in loading the current configuration file by .NET 2.0 application

Irfan Ahmed, Senior Support Escalation Engineer, recently was working on an issue where application was not loading the current configuration file. The application was developed on .NET 2.0 and working fine for some years now on different operating systems including Windows 8.0.

When the same application was deployed on Windows 8.1 or Windows Server 2012 R2, it throws an error with the following stack

'System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.Configuration.ConfigurationErrorsException: Unrecognized attribute 'Category'. Note that attribute names are case-sensitive. at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys,
SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object&
resultRuntimeObject)   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object&
resultRuntimeObject)   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,Boolean requestIsHere, Object& result, Object&
resultRuntimeObject)   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at

System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)

System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.ConfigurationManager.get_AppSettings()

[Background about application]

This is a windows service which host a remoting object. There are two config files in the application folder. One is TestApp.exe.config and the other one is ServerRemote.config.  the app.config has application setting and written in XML format i.e. it has values apart from Key and value in it.  The ServerRemote.config is a typical config file which has information about remoting object in Key-Value format. See the example below for both config file

 TestApp.exe.config

 <configuration>

  <appSettings>

    <add key="Address" value="Redmond" category="Mail Settings" description="Email Address." type="System.String"/>

  </appSettings>

</configuration>

 ServerRemote.config

 <configuration>

<system.runtime.remoting>

    <application>

      <channels>

 
<channel ref="tcp" port="5555">

 
<serverProviders>

 
<formatter ref="binary" typeFilterLevel="Full"/>

 
</serverProviders>

 
</channel>

      </channels>

  <service>

<wellknown mode="SingleCall" type="DMS.Spares.OpeningBalance.OpeningBalanceManager,Spares.OpeningBalance.Server"objectUri="SparesOpeningBalance.soap" />

</service>

   <client>

            
<wellknown type="CoreServices.Events.Interfaces.IServerEventBroker,CS.EventInterfaces" url="tcp://localhost:5555/ServerEventBroker.soap"/>

      </client>

    </application>

   <customErrors mode="off" />

  </system.runtime.remoting> 

</configuration>

 This issue can be easily reproduce by the having both the config files in the application directory and following code on a button click or in main method.

 System.Runtime.Remoting.RemotingConfiguration.Configure("ServerRemote.config", False)

 What happens is that though you are asking to read “ServerRemote.config” file, it still reads the AppTest.exe.config file which has different format which is not supported by System.configuration namespace.

  [Resolution]

 There is no specific fix which resolve this issue but installing the latest KB2908381  will resolve the issue in Windows 8.1 and Windows Server 2012 R2 as well.

 

Written and Reviewed by Irfan Ahmed, Senior Support Escalation Engineer, EMEA Team