Tôi đã viết một bài kiểm tra đơn giản sau đây để cố gắng học Giao diện Thông thạo của Castle Windsor:
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);
}
}
}
Khi tôi thực hiện kiểm tra thông qua TestDriven.NET, tôi gặp lỗi sau:
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()
Khi tôi thực hiện kiểm tra thông qua NUnit GUI, tôi nhận được:
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.
Nếu tôi mở Assembly mà tôi đang tham chiếu trong Reflector, tôi có thể thấy thông tin của nó là:
Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
và nó chắc chắn chứa Castle.MicroKernel.Registration.IRegistration
Điều gì có thể xảy ra?
Tôi nên đề cập rằng các tệp nhị phân được lấy từ bản dựng mới nhất của Castle mặc dù tôi chưa bao giờ làm việc với nant nên tôi không bận tâm đến việc biên dịch lại từ nguồn và chỉ lấy các tệp trong thư mục bin. Tôi cũng nên chỉ ra rằng dự án của tôi biên dịch không có vấn đề gì.
