本地和项目刚发布的时候没问题,过几个小时就会出现object does not match target 返回
出问题后,重新发布又没问题了。
以下报错信息:
【日志级别】:ERROR
【日志对象】:JJCK.Framework.Log.LogUtils
【日志内容】:System.Reflection.TargetException: Object does not match target type.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at SqlSugar.InsertableProvider`1.SetInsertItemByEntity(Int32 i, T item, List`1 insertItem)
at SqlSugar.InsertableProvider`1.Init()
at SqlSugar.SqlSugarProvider.CreateInsertable[T](T[] insertObjs)
at SqlSugar.SqlSugarProvider.Insertable[T](T[] insertObjs)
at SqlSugar.SqlSugarProvider.Insertable[T](T insertObj)
at SqlSugar.SqlSugarClient.Insertable[T](T insertObj)
at JJCK.Framework.Sqlsugar.Repository`1.InsertAsync(T entity) in /home/gitlab-runner/builds/4d1YxK6e/0/wanglianghua/MedicalRecord/JJCK.Framework/Sqlsugar/Repository.cs:line 386
at JJCK.Service.User.PatientService.AddAsync(AddPatientDto input) in /home/gitlab-runner/builds/4d1YxK6e/0/wanglianghua/MedicalRecord/JJCK.Service/User/PatientService.cs:line 74
at JJCK.Web.Controllers.PatientController.Add(AddPatientDto input) in /home/gitlab-runner/builds/4d1YxK6e/0/wanglianghua/MedicalRecord/JJCK.Web/Controllers/PatientController.cs:line 52
at lambda_method783(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
热忱回答(7)
-
fate stay night VIP0
2021/9/21. sqlsugar版本不是最新的就升级最新的,
2. 将sqlsugarclient 换成 SqlSugarScope
3. 如果还有问题 按这个模版写个API用例 https://www.donet5.com/Home/Doc?typeId=2366
0 回复 -
华哥很nice VIP0
2021/9/24接口方法
--------------------------------------------------------------------------------------
public IRepository<HospitalPatient> HospitalPatientRepository { get; set; }
public async Task<PatientModel> AddAsync(AddPatientDto input)
{
var a = new HospitalPatient
{
FirstVisitDoctorId = input.FirstVisitDoctorId,
HospitalId = (await UserHelper.GetCurrentUserAsync())?.Hospital?.Id,
PatientId = entity.Id,
Remark = input.Remark,
UnWriteRemindType = EnumUnWriteRemindType.NewUnWrite,
IsIgnoreRemind = false,
HospitalDoctorId = (await UserHelper.GetCurrentUserAsync())?.HospitalDoctor?.Id, //从登录信息取
};
await HospitalPatientRepository.InsertAsync(a);
}
仓储插入方法
----------------------------------------------------------------------------------------
public Task<int> InsertAsync(T entity)
{
//返回插入数据的标识字段值
return GetDb().Insertable(entity).ExecuteCommandAsync();
}
上下文:
————————————————————————————————————
public static SqlSugarScope GetSqlSugarClient(bool bl = true)
{
//创建数据库对象
SqlSugarScope db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = AppConfigurtaionHelper.GetSectionValue("ConnectionString"),//连接符字串
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute//从特性读取主键自增信息
});
if (bl)
{
db.QueryFilter.Add(new SqlFilterItem()
{
FilterName = null,
FilterValue = it =>
{
//Writable logic
return new SqlFilterResult() { Sql = $" DataStatus != {(int)EnumDataStatus.IsDeleted} " };
},
IsJoinQuery = false //单表查询生效
});
}
}
0 回复 -
fate stay night VIP0
2021/9/24就上面的代码是没问题的,你可以写个空API进行测试
0 回复 -
华哥很nice VIP0
2021/9/25这问题不是每次都会出现,就是挺莫名其妙的,本地执行一点问题没有,服务器刚发布也没问题,运行一段时间后就不行了。执行到: return GetDb().Insertable(entity).ExecuteCommandAsync();
这句代码的时候就报错了。有什么替换的方法吗
0 回复 -
fate stay night VIP0
2021/9/25@华哥很nice:你单独写个空的API 测试 ,能重现把API发我 , 测试方试,用个控制台程序 每多少时间请求一次 ,按上面的测试还有问题把API发我
0 回复 -
fate stay night VIP0
2021/9/25大概率不是你上面代码问题,想解决写个DEMO很容易解决
0 回复 -
fate stay night VIP0
2021/9/25你上面的代码在你的整个框架中太片面了,单纯上面的方法肯定是OK的,你可以测测看
0 回复