2010-06-02 29 views
5

我在溫莎城堡的XML文件下面的映射已經有一段時間效果不錯(不變):溫莎城堡升級導致TypeLoadException泛型類型

<component id="defaultBasicRepository" 
      service="MyApp.Models.Repositories.IBasicRepository`1, MyApp.Models" 
      type="MyApp.Models.Repositories.Linq.BasicRepository`1, MyApp.Models" 
      lifestyle="perWebRequest"/> 

我在http://www.castleproject.org/container/documentation/v1rc3/usersguide/genericssupport.html得到這個從溫莎文檔。

自從我升級溫莎,我現在在運行時出現以下情況例外:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: GenericArguments[0], 'T', on 'MyApp.Models.Repositories.Linq.BasicRepository`1[TEntity]' violates the constraint of type parameter 'TEntity'.

Source Error:

Line 44: public static void ConfigureIoC()
Line 45: {
Line 46: var windsor = new WindsorContainer("Windsor.xml");
Line 47:
Line 48: ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(windsor));

我使用ASP.NET MVC 1.0,Visual Studio 2008和溫莎城堡從http://sourceforge.net/projects/castleproject/files/InversionOfControl/2.1/Castle-Windsor-2.1.1.zip/download

能下載有人對此有何看法?我確信溫莎城堡的升級是造成它的原因 - 它已經運行良好很多年了。

UPDATE
我在最後自己修復了它。詳情請參閱下面的my answer

回答

8

我通過比較映射中的所有類/接口,最終找到了自己的答案。

答案是,BasicRepository的泛型類型參數有一個通用的限制如下:

public class BasicRepository<TEntity> : IBasicRepository<TEntity> 
    where TEntity : class 
{ 

...但它實現的接口並不具有相同的約束:

public interface IBasicRepository<T> 
{ 

我更新了接口匹配:

public interface IBasicRepository<T> 
    where T : class 
{ 

現在everythi ng正常工作。

希望這可以幫助別人。 :)