Ошибка, когда метод и пространство имен совпадают - PullRequest
0 голосов
/ 10 июля 2019

У меня есть 2 проекта, оба используют AutoMapper с одной и той же версией.Таким образом, оба проекта должны настроить профиль с помощью этого кода

 public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            //CreateMap goes here
        }       
    }

Как видите, я унаследую класс Profile от AutoMapper.Но проблема случится на другом проекте.

Пространство имен для этого проекта Profile.API.Итак, что случилось, я получил ошибку 'Profile' is a namespace but is used like a type

Вот мой полный код для класса AutoMapperProfile

using AutoMapper;


namespace Profile.API.Infrastructure.AutoMapper
{
    public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            //CreateMap goes here
        }       
    }
}

Нужен совет

1 Ответ

1 голос
/ 10 июля 2019

Дайте Automapper using псевдоним:

using AM = AutoMapper;

namespace Profile.API.Infrastructure.AutoMapper
{
    public class AutoMapperProfile : AM.Profile
    {
        public AutoMapperProfile()
        {
            //CreateMap goes here
        }
    }
}
...