DapperLib / DapperLib/Dapper

About the SQLMapper addTypeHandler exception

Open
#1,685 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

` public class JsonConvertHandler : SqlMapper.TypeHandler
{
public override T Parse(object value)
{
return JsonConvert.DeserializeObject((string)value);
}

    public override void SetValue(IDbDataParameter parameter, T value)
    {
        parameter.Value = JsonConvert.SerializeObject(value);
    }
}`

StringBuilder strSql = new StringBuilder(); strSql.Append("select ruleid, websetting, createtime, rulename, userid, offstarttime, offendtime, replacestr, payrate, paymodel, limitsetting ,isuse "); strSql.Append(" from TB_U_UserPay_Rule "); strSql.Append(" where ruleid=@ruleid"); SqlMapper.AddTypeHandler(new JsonConvertHandler<UserPay_Rule_LimitModel>()); SqlMapper.AddTypeHandler(new JsonConvertHandler<UserPay_Rule_WebModel>()); return DapperHelper.QuerySingleOrDefault<TB_U_UserPay_RuleModel>(strSql.ToString(), new { ruleid });

System.Data.DataException: Error parsing column 1 (websetting={"iswebshow":1,"moneytype":1,"showminmoney":0.0,"logo":null,"sevicelink":null,"gamesitelink":null,"notice":null} - String) ---> System.InvalidCastException: 从“System.String”到“GamePal.Model.UserPay.UserPay_Rule_WebModel”的强制转换无效

It is not certain why this anomaly occurs, but it is most likely to occur after the hot update site,After the application pool is reclaimed, the exception disappears

I'm now trying to do this when the application starts up, but that remains to be seen
protected void Application_Start() { SqlMapper.ResetTypeHandlers(); }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported SqlMapper.AddTypeHandler calls and the Application_Start ResetTypeHandlers call, then trace the QuerySingleOrDefault path that parses websetting. Reproduce the hot-update or application-pool-recycle condition described in the report. Done means the cause of the invalid cast is identified and a verified resolution or clear limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.