Castle Windsor の Fluent Interface を学習するために、次の簡単なテストを作成しました。
using NUnit.Framework;
using Castle.Windsor;
using System.Collections;
using Castle.MicroKernel.Registration;
namespace WindsorSample {
public class MyComponent : IMyComponent {
public MyComponent(int start_at) {
this.Value = start_at;
}
public int Value { get; private set; }
}
public interface IMyComponent {
int Value { get; }
}
[TestFixture]
public class ConcreteImplFixture {
[Test]
public void ResolvingConcreteImplShouldInitialiseValue() {
IWindsorContainer container = new WindsorContainer();
container.Register(Component.For<IMyComponent>().ImplementedBy<MyComponent>().Parameters(Parameter.ForKey("start_at").Eq("1")));
IMyComponent resolvedComp = container.Resolve<IMyComponent>();
Assert.AreEqual(resolvedComp.Value, 1);
}
}
}
TestDriven.NET を通じてテストを実行すると、次のエラーが発生します。
System.TypeLoadException : Could not load type 'Castle.MicroKernel.Registration.IRegistration' from assembly 'Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'.
at WindsorSample.ConcreteImplFixture.ResolvingConcreteImplShouldInitialiseValue()
NUnit GUI を通じてテストを実行すると、次の結果が得られます。
WindsorSample.ConcreteImplFixture.ResolvingConcreteImplShouldInitialiseValue:
System.IO.FileNotFoundException : Could not load file or assembly 'Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The system cannot find the file specified.
Reflector で参照しているアセンブリを開くと、次の情報が表示されます。
Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
そしてそれは間違いなくCastle.MicroKernel.Registration.IRegistration
何が起こっているのでしょうか?
バイナリは、城の最新ビルドただし、私は nant を使ったことがないので、ソースから再コンパイルする手間をかけずに、bin ディレクトリ内のファイルを取得しました。また、私のプロジェクトは問題なくコンパイルされることも指摘しておきます。
ベストアンサー1
あるプロジェクトが別のプロジェクトを参照しており (「Windows アプリケーション」タイプが「クラス ライブラリ」を参照しているなど)、両方のアセンブリ名が同じである場合、このエラーが発生します。参照先プロジェクトに厳密な名前を付けるか、(さらに良い方法として) 参照元プロジェクトのアセンブリ名を変更します (VS のプロジェクト プロパティの「アプリケーション」タブで)。