How to resolve Castle.Windsor and MoQ version conflicts for Castle.Core assembly
Asked Answered
P

1

5

In my project I need to use simultaneously Castle.Windsor and Moq dlls. Windsor requires Castle.Core also to be referenced in the project.

Problem starts when I try to use methods from Castle.Core: Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(...);

Problem1: If I use Moq.dll from NET40 folder, I got built error "The type 'Castle.DynamicProxy.Generators.AttributesToAvoidReplicating' exists in both '...\Windsor\dotNet40\Castle.Core.dll' and '...\MoQ\NET40\Moq.dll'"

Problem2: If I use Moq.dll from "NET40-RequiresCastle" folder, which is logically in my situation, I got versions conflict - Moq.dll uses Castle.Core, Version=2.5.0.0, but Windsor uses Castle.Core, Version=2.5.1.0

Postbellum answered 11/11, 2011 at 14:17 Comment(2)
Moq is used for unit test. During unit testing, you really shouldn't be using your IoC container (Windsor). What's the use case that you need to use Windsor in your unit tests with Moq? Or are you using Moq in production code with Windsor?Hairspring
Thank you, Patrick, for you comment. I've solved my problem - see answer.Postbellum
P
9

Problem can be solved using assembly binding - App.config:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" />
    <bindingRedirect oldVersion="1.0.0.0-2.5.0.0" newVersion="2.5.1.0" />
  </dependentAssembly>
</assemblyBinding>
Postbellum answered 15/11, 2011 at 9:58 Comment(1)
now that's a piece you don't see very often. +1 for reminding me on that:)Turin

© 2022 - 2024 — McMap. All rights reserved.