添加对 Ninject.Extensions.Interception.DynamicProxy 的引用会导致不明确的匹配异常

发布于 2024-10-21 12:36:19 字数 2477 浏览 8 评论 0原文

我已将 Ninject 配置为在 ASP.NET MVC 3 应用程序中执行 DI。这工作正常,它将正确的类注入到我的控制器中。

当我尝试添加 Ninject.Extensions.Interception 来处理我的应用程序时,我开始收到不明确的匹配异常。仅当我添加 Ninject.Extensions.Interception.DynamicProxy 程序集时才会发生这种情况。如果我删除这个程序集,它就会再次正常运行。我还引用了 Ninject.Extensions.Intereception 和 Castle.Core。

请注意,我没有在应用程序中配置拦截。我只是添加一个引用,这个错误就开始发生。

我正在使用 Ninject 2.2.1.0 和 Ninject.Extensions.Interception 2.2.0.0。

private const BindingFlags DefaultBindingFlags =
    BindingFlags.Public |
    BindingFlags.NonPublic |
    BindingFlags.Instance;

public static PropertyInfo GetPropertyFromMethod( this MethodInfo method, Type implementingType )
{
    if ( !method.IsSpecialName )
    {
        return null;
    }

    return implementingType.GetProperty( method.Name.Substring( 4 ), DefaultBindingFlags );
}

堆栈跟踪:

[AmbigouslyMatchException:不明确 找到匹配项。]
System.RuntimeType.GetPropertyImpl(字符串 名称、BindingFlags 绑定属性、绑定器 活页夹,类型 returnType,Type[] 类型, ParameterModifier[] 修饰符) +9402677 System.Type.GetProperty(字符串名称, BindingFlags(绑定属性)+31
Ninject.Extensions.Interception.Infrastruct.Language.ExtensionsForMethodInfo.GetPropertyFromMethod(MethodInfo 方法,类型实现类型)中 c:\Projects\Ninject\ninject.extensions.interception\src\Ninject.Extensions.Interception\Infrastruct\Language\ExtensionsForMethodInfo.cs:35 Ninject.Extensions.Interception.Planning.Strategies.InterceptorRegistrationStrategy.Execute(IPlan 计划)中 c:\ Projects \ Ninject \ ninject.extensions.interception \ src \ Ninject.Extensions.Interception \ Planning \ Strategies \ InterceptorRegistrationStrategy.cs:83 Ninject.Planning。<>c_DisplayClass3.b_1(IPlanningStrategy s) 在 c:\Projects\Ninject\ninject\src\Ninject\Planning\Planner.cs:68 Ninject.Infrastruct.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable1 系列,动作1动作)中 c:\Projects\Ninject\ninject\src\Ninject\Infrastruct\Language\ExtensionsForIEnumerableOfT.cs:23 Ninject.Planning.Planner.GetPlan(类型 类型)输入 c:\Projects\Ninject\ninject\src\Ninject\Planning\Planner.cs:68 Ninject.Activation.Providers.StandardProvider.Create(IContext 上下文)中 c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:74 Ninject.Activation.Context.Resolve() 在 c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:157 Ninject.KernelBase.b__7(IContext 上下文)中 c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:375

I have Ninject configured to do DI in an ASP.NET MVC 3 application. This is working fine and it injects the proper classes in to my controllers.

When I try and add Ninject.Extensions.Interception to work with my application I start getting an ambiguous match exception. This only happens when I add the Ninject.Extensions.Interception.DynamicProxy assembly. If I remove this assembly then it runs fine again. I also have referenced Ninject.Extensions.Intereception and Castle.Core.

Note that I have not configured interception in the application. I am just adding a reference and this error starts happening.

I am using Ninject 2.2.1.0 and Ninject.Extensions.Interception 2.2.0.0.

private const BindingFlags DefaultBindingFlags =
    BindingFlags.Public |
    BindingFlags.NonPublic |
    BindingFlags.Instance;

public static PropertyInfo GetPropertyFromMethod( this MethodInfo method, Type implementingType )
{
    if ( !method.IsSpecialName )
    {
        return null;
    }

    return implementingType.GetProperty( method.Name.Substring( 4 ), DefaultBindingFlags );
}

Stack trace:

[AmbiguousMatchException: Ambiguous
match found.]
System.RuntimeType.GetPropertyImpl(String
name, BindingFlags bindingAttr, Binder
binder, Type returnType, Type[] types,
ParameterModifier[] modifiers)
+9402677 System.Type.GetProperty(String name,
BindingFlags bindingAttr) +31
Ninject.Extensions.Interception.Infrastructure.Language.ExtensionsForMethodInfo.GetPropertyFromMethod(MethodInfo
method, Type implementingType) in
c:\Projects\Ninject\ninject.extensions.interception\src\Ninject.Extensions.Interception\Infrastructure\Language\ExtensionsForMethodInfo.cs:35
Ninject.Extensions.Interception.Planning.Strategies.InterceptorRegistrationStrategy.Execute(IPlan
plan) in
c:\Projects\Ninject\ninject.extensions.interception\src\Ninject.Extensions.Interception\Planning\Strategies\InterceptorRegistrationStrategy.cs:83
Ninject.Planning.<>c_DisplayClass3.b_1(IPlanningStrategy
s) in
c:\Projects\Ninject\ninject\src\Ninject\Planning\Planner.cs:68
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable1
series, Action
1 action) in
c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:23
Ninject.Planning.Planner.GetPlan(Type
type) in
c:\Projects\Ninject\ninject\src\Ninject\Planning\Planner.cs:68
Ninject.Activation.Providers.StandardProvider.Create(IContext
context) in
c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:74
Ninject.Activation.Context.Resolve()
in
c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:157
Ninject.KernelBase.b__7(IContext
context) in
c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:375

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心奴独伤 2024-10-28 12:36:19

已在 Ninject.Extensions.Interception 2.2.1.0 中修复

Fixed in Ninject.Extensions.Interception 2.2.1.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文