JeffreySu/WeiXinMPSDK · error · ConfigurationErrorsException

Section is not found.

Error message

Section {sectionName} is not found.

What it means

RedisConfigInfo.GetConfig reads a custom configuration section (RedisConfigInfo) from app.config/web.config via ConfigurationManager.GetSection. If the section name does not resolve to a configured section it throws ConfigurationErrorsException. The library requires the Redis cache section to be declared with the correct type in the configSections block.

Solutions

  1. Add the <configSections><section name="..." type="...RedisConfigInfo, Senparc.Weixin.Cache.Redis"/> declaration and the section XML with WriteServerList/ReadServerList etc.
  2. Verify the sectionName string passed to GetConfig matches the config exactly (case and spelling)
  3. Ensure the correct app.config/web.config is deployed to the runtime output directory
  4. If using ConfigHelper instead, call Senparc.Weixin.ConfigHelper.RegisterConfigFile or rely on auto registration so the section is created

Example fix

<!-- before: no section declared -->
<!-- after -->
<configSections>
  <section name="Senparc.RedisConfig" type="Senparc.Weixin.Cache.Redis.ServiceStack.Redis.RedisConfigInfo, Senparc.Weixin.Cache.Redis" requirePermission="false"/>
</configSections>
<Senparc.RedisConfig WriteServerList="..." ReadServerList="..." MaxReadPoolSize="" MaxWritePoolSize="" AutoStart="true" LocalCacheTime="" RecordeLog="false"/>
Defensive patterns

Strategy: validation

Validate before calling

var section = ConfigurationManager.GetSection("Senparc.RedisConfig") as RedisConfigInfo;
if (section == null) throw new InvalidOperationException("Add <configSections><section name=... type=...RedisConfigInfo...> and the section XML to your .config");

Try / catch

try { var cfg = RedisConfigInfo.GetConfig("Senparc.RedisConfig"); }
catch (ConfigurationErrorsException ex) { log.Error("Redis config section missing: " + ex.Message); throw new InvalidOperationException("Register the Redis config section in app.config/web.config", ex); }

Prevention

When it happens

Trigger: Calling RedisConfigInfo.GetConfig("sectionName") where the .config file lacks a <section name="sectionName" type="Senparc.Weixin.Cache.Redis...RedisConfigInfo"> registration, or the section element itself is absent, or the name is misspelled.

Common situations: Deploying to a new server without copying the config section, renaming the section in code but not in config, missing the configSections declaration, running a project that uses the Redis cache without adding its configuration.

Related errors


AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12). Data as JSON: /api/errors/fea01c653f7b1c67. Report an issue: GitHub.

Appendix: source

Thrown at src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Redis/ServiceStack.Redis/RedisConfigInfo.cs:34

        /// 获取配置信息,默认配置节点名称为RedisConfig
        /// </summary>
        /// <returns></returns>
        public static RedisConfigInfo GetConfig()
        {
            RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection("RedisConfig");
            return section;
        }

        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="sectionName">配置节点的sectionName</param>
        /// <returns></returns>
        public static RedisConfigInfo GetConfig(string sectionName)
        {
            RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection(sectionName);
            if (section == null)
                throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
            return section;
        }
        /// <summary>
        /// 可写的Redis链接地址
        /// </summary>
        [ConfigurationProperty("WriteServerList", IsRequired = false)]
        public string WriteServerList
        {
            get
            {
                return (string)base["WriteServerList"];
            }
            set
            {
                base["WriteServerList"] = value;
            }
        }

View on GitHub (pinned to be573f6f94)