JeffreySu/WeiXinMPSDK · error · WeixinException

请统一使用请统一使用Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccou…

Error message

请统一使用请统一使用Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount()方法进行注册!

What it means

RegisterWxOpenAccount(this IRegisterService, ...) extension method is marked [Obsolete] and unconditionally throws WeixinException telling developers to use the unified Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount() static registration method instead. Only the parameterless/static form is supported.

Solutions

  1. Replace the call with the static Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount(appId, appSecret, name)
  2. Use RegisterWxOpenAccount(...) overload accepting SenparcWeixinSettingItem to register from configuration
  3. Update startup code (usually in startup.cs / Global.asax) to the new API

Example fix

// before
services.AddSenparcWeixinServices(...);
registerService.RegisterWxOpenAccount(appId, appSecret, name); // throws
// after
Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount(appId, appSecret, name);
// or from settings:
Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount(senparcWeixinSettingItem);
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: calling this [Obsolete] method triggers a compiler warning — fix before release.

Prevention

When it happens

Trigger: Calling the deprecated extension form registerService.RegisterWxOpenAccount(appId, appSecret, name) during app startup configuration of a WxOpen (mini-program) account.

Common situations: Copy-paste from old samples or blog posts; migration from older Senparc.Weixin versions where the extension method was valid.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Register.cs:65

namespace Senparc.Weixin.WxOpen
{
    /// <summary>
    /// 注册小程序
    /// </summary>
    public static class Register
    {
        /// <summary>
        /// 注册小程序信息
        /// </summary>
        /// <param name="registerService">RegisterService</param>
        /// <param name="appId">微信公众号后台的【开发】>【基本配置】中的“AppID(应用ID)”</param>
        /// <param name="appSecret">微信公众号后台的【开发】>【基本配置】中的“AppSecret(应用密钥)”</param>
        /// <param name="name">标记AccessToken名称(如微信公众号名称),帮助管理员识别</param>
        /// <returns></returns>
        [Obsolete("请统一使用Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount()方法进行注册!")]
        public static IRegisterService RegisterWxOpenAccount(this IRegisterService registerService, string appId, string appSercet, string name = null)
        {
            throw new WeixinException("请统一使用请统一使用Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount()方法进行注册!");
        }

        /// <summary>
        /// 根据 SenparcWeixinSetting 自动注册小程序信息
        /// </summary>
        /// <param name="registerService">RegisterService</param>
        /// <param name="weixinSettingForWxOpen">SenparcWeixinSetting</param>
        /// <param name="name">统一标识,如果为null,则使用 SenparcWeixinSetting.ItemKey </param>
        /// <returns></returns>
        public static IRegisterService RegisterWxOpenAccount(this IRegisterService registerService, ISenparcWeixinSettingForWxOpen weixinSettingForWxOpen, string name = null)
        {
            //配置全局参数
            if (!string.IsNullOrWhiteSpace(name))
            {
                Config.SenparcWeixinSetting[name] = new SenparcWeixinSettingItem(weixinSettingForWxOpen);
            }
            AccessTokenContainer.Register(weixinSettingForWxOpen.WxOpenAppId, weixinSettingForWxOpen.WxOpenAppSecret, name ?? weixinSettingForWxOpen.ItemKey);
            return registerService;

View on GitHub (pinned to be573f6f94)