[Mono-list] Configuration.SectionGroups type cast problem

Danny Gorton dgortonii at gmail.com
Mon Aug 24 14:38:11 UTC 2015

Hello all.  I searched the list archives (using google) and couldn't find
anything related to this issue.

My environment is:

Linux raspberrypi 3.12.35+ #730 PREEMPT Fri Dec 19 18:31:24 GMT 2014 armv6l
GNU/Linux and Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4+rpi1).
I develop on Windows with VS.NET and automate builds on Linux/Mono and test
on Windows and Raspbian (ARM) and Ubuntu.  Most of the time it *just
works*, but every once in a while I run into some weird differences between
.NET and Mono.

My product is a daemon with ServiceStack 3.9.x embedded to provide web
services.  I have features for altering server configuration options
through a web UI.  When that web service is called it looks for specific
ConfigurationSection instances (some custom, some standard) by iterating
the configuration hierarchy, through the SectionGroups
(ConfigurationSectionGroupCollection) on downward until it finds a match.
Here is one example:

            foreach (Config.ConfigurationSectionGroup group in

In this code _config is a System.Configuration.Configuration instance and
this code works on .NET (Windows 7), but breaks on Mono on the foreach line

System.InvalidCastException: Cannot cast from source type to destination

For some reason the contents of SectionGroups don't seem to be
ConfigurationSectionGroup objects. So I put in some debug logging like this:

            if (_log.IsDebugEnabled)
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(string.Format("Configuration has [{0}]
section groups:", _config.SectionGroups.Count));
                foreach(object o in _config.SectionGroups)
                    sb.AppendLine(string.Format("\tSectionGroup of type:
[{0}] is [{1}]", o.GetType().FullName, o));

The output on .NET shows the right types (don't have an example handy right
now).  The output on Mono looks like:

2015-08-23 21:59:14,945 [Threadpool worker] DEBUG raspberrypi
ConfigurationHandler.getSection (line 0) - Configuration has [5] section
        SectionGroup of type: [System.String] is [system.web]
        SectionGroup of type: [System.String] is [system.net]
        SectionGroup of type: [System.String] is [system.serviceModel]
        SectionGroup of type: [System.String] is [system.transactions]
        SectionGroup of type: [System.String] is [apac]

As you can see, the types are string and the values are the names of the
section groups in question.  I've looked at the code history for
ConfiguratoinSectionGroupCollection and Configuration.SectionGroups and I
don't see where either was ever written to store just simple strings,
though I may be missing something.

My <configSections> element is:
    <sectionGroup name="apac"
type="System.Configuration.ConfigurationSectionGroup, System.Configuration,
Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <section name="default"
type="Apac.Configuration.XmlSerializingConfigSection, apac.core"/>
      <section name="pluginPaths"
type="Apac.Configuration.NameMultipleValueSectionHandler, apac.core"/>
      <!-- APAC Messaging Configuration-->
 type="Apac.Configuration.MessageControllerConfigSection, apac.core"
 restartOnExternalChanges="true" />

      <!-- APAC Licensing Configuration-->
      <section name="apac.licensing"


Anyone have any idea why this would be happening?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20150824/f122552c/attachment.html>

More information about the Mono-list mailing list