【发布时间】:2022-08-04 10:29:55
【问题描述】:
好吧,在从 net core 3.1 升级到 .NET 5 之前,这个曾经很好用
产生错误的扩展方法是
public static IQueryable Set(this myContext context, Type T)
{
MethodInfo method = typeof(myContext).GetMethod(nameof(myContext.Set), BindingFlags.Public | BindingFlags.Instance);
method = method.MakeGenericMethod(T);
return method.Invoke(context, null) as IQueryable;
}
尤其是这条线
MethodInfo method = typeof(myContext).GetMethod(nameof(myContext.Set), BindingFlags.Public | BindingFlags.Instance);
堆栈跟踪是
at System.RuntimeType.GetMethodImplCommon(String name, Int32 genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name, BindingFlags bindingAttr)
at Extensions.QueryableExtensions.Set(RetailContext context, Type T, Boolean dummy) in QueryableExtensions.cs:line 36
这个模棱两可的错误来自哪里?
-
不够,咳咳,上下文。例如。什么是
myContext.Set(它是如何声明的)? -
请共享足够的代码,并且您的堆栈跟踪也不完整。
-
不回答您的问题,但您应该迁移到 net6,因为 net5 已经 EOL dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core
-
听起来有不止一种方法具有该名称。
Set是否过载?
标签: c# asp.net-core .net-core .net-5 .net-core-3.1