WindsorContainer.Register()中的“System.ArgumentNullException”。值不能为空。参数名称:名称

时间:2014-11-08 02:39:50

标签: castle-windsor

我尝试从aspnetboilerplate开始编写代码。

调用WindsorContainer类函数

public void Register(Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)

看起来像这样:

iocManager.Register(
                        typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType),
                        typeof(EfRepositoryBase<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType),
                        DependencyLifeStyle.Transient
                        );

支持类型是:

[System.RuntimeType] = {Name = "IRepository`2" FullName = "Abp.Domain.Repositories.IRepository`2"}

base = {Name = "EfRepositoryBase`3" FullName = null}

我们可以看到由MakeGenericType()具体类型的FullName实例化的是null

班级EfRepositoryBase3如下所示:

 public class EfRepositoryBase<TDbContext, TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
        where TEntity : class, IEntity<TPrimaryKey>
        where TDbContext : DbContext
    {
         ... CRUD methods...
    }

为什么FullName null是{{1}}以及如何克服这个问题?

1 个答案:

答案 0 :(得分:1)

在某些情况下,

FullName可以返回null

  

Type的完全限定名称,包括。的名称空间   键入但不是组件;如果当前实例表示,则返回null   泛型类型参数,数组类型,指针类型或byref类型   基于类型参数或非泛型的泛型类型   类型定义但包含未解析的类型参数。

您可以使用GetGenericTypeDefinition方法获取非空名称。