无法解析类型名称或别名xxxx。请检查配置文件并验证此类型名称

时间:2015-02-27 18:26:32

标签: asp.net-mvc unity-container

我在RepositoryPattern项目中定义了以下接口:

using System.Collections.Generic;
using Domain;

namespace RepositoryPattern
{
    public interface IRepository
    {
        List<Car> GetCars();
    }
}

我的XML配置的统一部分如下所示:

  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <namespace name="RepositoryPattern" />
    <container>
      <register type="IRepository" mapTo="SqlServerRepository" />
    </container>
  </unity>

运行应用程序时,出现以下错误:

The type name or alias IRepository could not be resolved. Please check your configuration file and verify this type name.

1 个答案:

答案 0 :(得分:2)

我明白了。我需要添加汇编部分:

  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <assembly name ="RepositoryPattern"/>
    <namespace name="RepositoryPattern" />
    <container>
      <register type="IRepository" mapTo="SqlServerRepository" />
    </container>
  </unity>