2013-01-10 33 views
0

我試圖運行一些集成測試,並使用此:的SQLite + windsor.castle版本問題

public class ServiceLocatorInitializer 
{ 
public static void Init() 
{ 
    IWindsorContainer container = new WindsorContainer(); 

    container.Register(
     Component 
     .For(typeof(IEntityDuplicateChecker)) 
     .ImplementedBy(typeof(EntityDuplicateChecker)) 
     .Named("entityDuplicateChecker")); 

    container.Register(
     Component.For(typeof(ISessionFactoryKeyProvider)) 
     .ImplementedBy(typeof(DefaultSessionFactoryKeyProvider)) 
     .Named("sessionFactoryKeyProvider")); 

    ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); 
} 
} 

加上這樣的:

<?xml version="1.0" encoding="utf-8" ?> 
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
     <session-factory> 
     <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
     <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
     <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
     <property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property> 
     <property name="connection.release_mode">on_close</property> 
     <property name="show_sql">true</property> 
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
     </session-factory> 
    </hibernate-configuration> 

我不得不Castle.Windsor 3.1版的參考。 0.0但是得到這個錯誤:

Could not load file or assembly 'Castle.Windsor, Version=2.5.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

不知道是什麼原因以及如何克服這個問題?謝謝。

回答

3

WindsorServiceLocator是針對舊版本的Castle構建的,尚未更新。

您需要在您的測試項目App.Config中添加BindingRedirect,你應該能夠在Visual Studio中打開NuGet包管理器控制檯添加它們,選擇測試項目,並運行

Add-BindingRedirect 

檢查App.Config,您現在應該擁有裝配的綁定重定向。

+0

我想我已經試過了。稍後再檢查一次。感謝Seif! – cs0815

1

NHibernate.ByteCode.Castle對Castle有依賴性,因爲它使用DynamicProxy作爲它的代理工廠。 NHibernate 3.2解決了這個問題,它有自己的代理工廠,並且不依賴於Castle。如果可能,請將NHibernate升級到至少3.2,並從nhibernate配置文件中刪除proxyfactory配置。

+0

謝謝我的nhibernate.dll版本是3.3.1.4000,我已經刪除了proxyfactory行。問題依然存在... – cs0815

+0

任何其他與Castle Windsor有關的第三方庫? –