城堡DynamicProxy拦截器具有不同组件的问题 [英] Castle DynamicProxy Interceptor having problems with different assemblies

查看:333
本文介绍了城堡DynamicProxy拦截器具有不同组件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个场景:

这是引用我使用拦截器捕捉到一类是内部组件(姑且称之为功能)的调用主营项目。装配特征是通过安装的NuGet(它不公开,但我们的内部之一),并具有一定的参考到另一个组件(我们称之为核心)。主要项目是引用组件的堆芯为好。核心包含用作参数类型的拦截方法之一的类定义。

I'm using interceptor to catch calls to a class that is inside assembly (let's call it Feature) that is referenced by main project. Assembly Feature is installed by NuGet (it's not public but our internal one) and has reference to another assembly (let's call it Core). Main project is referencing assembly Core as well. Core contains class definition that is used as an argument type of one of the intercepted methods.

只要这一切工作正常作为主要项目的特点是引用相同版本核心库。当这个版本是不同的拦截方法从核心使用类型作为一个方法的参数问题出现了。

It all works fine as long as Main project and Feature are referencing the same version of Core library. Problem arises when this versions are different and intercepted method uses types from Core as a method arguments.

在这种情况下,抛出一个异常,各国需要一个强命名程序集

In this situation, an exception is thrown that states A strongly-named assembly is required.:

[FileLoadException: Could not load file or assembly 'Core, Version=0.2.2.30, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)] 
 Castle.Proxies.Invocations.IBasketService_Update.InvokeMethodOnTarget() +0
 Castle.DynamicProxy.AbstractInvocation.Proceed() +116
 Project.Basket.BasketServiceUpdatedInterceptor.Intercept(IInvocation invocation) in c:\(...)\Basket\BasketServiceUpdatedInterceptor.cs:20
 Castle.DynamicProxy.AbstractInvocation.Proceed() +604
 Castle.Proxies.IBasketServiceProxy.Update(ProductId productId, UInt16 quantity) +210 (...)

其中核心0.2版本。 2.30是装配特征期待,主体工程采用例如版本0.2.2.31版本。城堡DynamicProxy是无法找到核心与0.2.2.30版本,这是正确的,因为这确切组件未部署到bin文件夹。

Where version of Core 0.2.2.30 is a version that assembly Feature is expecting, main project is using for example version 0.2.2.31. Castle DynamicProxy is not able to find Core with version 0.2.2.30 and that's right because this exact assembly is not deployed to bin folder.

请注意,不同版本的核心是一种情况,我们的场景完全正常的。功能组件期待的版本高于规定 - 而不是确切的版本

Please note that different versions of Core are a situation perfectly normal in our scenario. Feature assembly is expecting version higher than specified - not exact version.

我不知道DynamicProxy是否应为刚性较差,在它的装配预期是我必须接受这个局限性。我已经写了简单的代理类来解决这个问题,所以它不会从我们的解决方案使用DynamicProxy阻止我了,但它阻止我们。

I'm not sure whether DynamicProxy should be less rigid in it's assembly expectations are I do have to accept this limitation. I've written simple proxy class to overcome this problem so it does not block me anymore yet it blocks us from using DynamicProxy in our solutions.

推荐答案

的问题是由DP来针对一个签名的程序集生成,然后被使用的组件的无符号版本的事实引起的。

The problem is caused by the fact that DP was generated against a signed assembly and then an unsigned version of the assembly is being used.

的解决方案是任以确保您使用签名的程序集在这两种情况下,或迫使DynamicProxy只生成未签名程序集。

The solution is either to ensure that you use signed assembly in both cases, or to force DynamicProxy to only generate unsigned assembly.

这篇关于城堡DynamicProxy拦截器具有不同组件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆