gpt4 book ai didi

namespaces - 在引用 NSubstitute 的程序集中使用 DynamicProxy 类型时如何修复 "type exists in both assemblies"故障?

转载 作者:行者123 更新时间:2023-12-04 02:09:25 25 4
gpt4 key购买 nike

我有一个使用 DynamicProxy 的应用程序3.1 做运行时拦截。我有一个使用 NSubstitute 的测试程序集 mock 。我刚刚针对完全自举的容器(使用 InterceptWith 进行拦截的 StructureMap)编写了一些“集成”测试,以便我可以断言从容器中出来的某些类型已被正确代理。

[Subject(typeof(RobotBoard))]
public class When_resolving_an_intercepted_type : WithContainer<IRobotBoard>
{
It should_have_recovery = () => Subject.ShouldHaveInterceptor<RecoveryInterceptor>();
}

public static class TestExtensions
{
public static void ShouldHaveInterceptor<T>(this object obj)
where T : IInterceptor
{
((IProxyTargetAccessor)obj)
.GetInterceptors()
.ToList()
.Exists(x => x is T)
.ShouldBeTrue();
}
}

但是,我收到此错误,表明 DynamicProxy 引用也在 NSubstitute 程序集中内部! (它似乎被 ilmerged)。

Error    11    MyCompany.MyModule.Specifications    D:\code\source\tests\When_resolving_an_intercepted_type.cs
The type 'Castle.DynamicProxy.IProxyTargetAccessor' exists in both 'd:\code\packages\Castle.Core.3.1.0\lib\net40-client\Castle.Core.dll' and 'd:\code\packages\NSubstitute.1.4.2.0\lib\NET40\NSubstitute.dll'

这个冲突到底有没有?

最佳答案

您可以获取 NSubstitute source code并从项目的目标中删除 ilmerge 命令。我打开了issue 86在他们的存储库中解决这个问题。

<exec command="&quot;$(MSBuildProjectDirectory)\..\..\ThirdParty\Ilmerge\ILMerge.exe&quot; /internalize:&quot;$(MSBuildProjectDirectory)\ilmerge.exclude&quot; /keyfile:$(AssemblyOriginatorKeyFile) /out:@(MainAssembly)  &quot;@(IntermediateAssembly)&quot; @(AssembliesToMerge->'&quot;%(FullPath)&quot;', ' ')" Condition=" '$(TargetFrameworkVersion)' == 'v3.5'" />
<exec command="&quot;$(MSBuildProjectDirectory)\..\..\ThirdParty\Ilmerge\ILMerge.exe&quot; /internalize:&quot;$(MSBuildProjectDirectory)\ilmerge.exclude&quot; /keyfile:$(AssemblyOriginatorKeyFile) /out:@(MainAssembly) /targetplatform:&quot;v4,$(FrameworkReferenceAssemblyPath).&quot; &quot;@(IntermediateAssembly)&quot; @(AssembliesToMerge->'&quot;%(FullPath)&quot;', ' ')" Condition=" '$(TargetFrameworkVersion)' == 'v4.0'" />

关于namespaces - 在引用 NSubstitute 的程序集中使用 DynamicProxy 类型时如何修复 "type exists in both assemblies"故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12266279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com