Error using AutoMapper "Class Not Found"

0

I'm studying the use of AutoMapper , however I get an error in my project.

  

AutoMapper Version: v3.3.1

I added Config to my Global.asax, ficando assim:

 protected void Application_Start()
        {
            AutoMapperConfig.RegisterMappings();
        }

My AutoMapperConfig looks like this:

public class AutoMapperConfig
    {
        public static void RegisterMappings()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.AddProfile<DomainToViewModelMappingProfile>();
                cfg.AddProfile<ViewModelToDomainMappingProfile>();
            });
        }
    }

My class DomainToViewModelMappingProfile looks like this:

public class DomainToViewModelMappingProfile : Profile
    {
        public override string ProfileName
        {
            get { return "DomainToViewModelMappings"; }
        }

        protected override void Configure()
        {
            Mapper.CreateMap<Pessoa, PessoaViewModel>();
            Mapper.CreateMap<Endereco, EnderecoViewModel>();
            Mapper.CreateMap<Pessoa, PessoaEnderecoViewModel>();
            Mapper.CreateMap<Endereco, PessoaEnderecoViewModel>();
        }
    }

and ViewModelToDomainMappingProfile looks like this:

public class ViewModelToDomainMappingProfile : Profile
    {
        public override string ProfileName
        {
            get { return "ViewModelToDomainMappings"; }
        }

        protected override void Configure()
        {
            Mapper.CreateMap<PessoaViewModel, Pessoa>();
            Mapper.CreateMap<EnderecoViewModel, Endereco>();
            Mapper.CreateMap<PessoaEnderecoViewModel, Pessoa>();
            Mapper.CreateMap<PessoaEnderecoViewModel, Endereco>();
        }
    }

By "mapping" the class in my AppService like this:

 public void Adicionar(PessoaEnderecoViewModel pessoaEnderecoViewModel)
    {

        var pessoa = Mapper.Map<PessoaEnderecoViewModel, Pessoa>(pessoaEnderecoViewModel);
        var endereco = Mapper.Map<PessoaEnderecoViewModel, Endereco>(pessoaEnderecoViewModel);

        pessoa.Enderecos.Add(endereco);
        _pessoaRepository.Add(pessoa);
    }

When debugging, when I get to this part var pessoa = Mapper.Map(pessoaEnderecoViewModel); I get the following error:

  

Mapper.cs not found

Locating source for 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'. Checksum: MD5 {28 13 88 2d fa c bf 90 0 c9 9c 25 64 11 3d 36}
The file 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs' does not exist.
Looking in script documents for 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'...
Looking in the projects for 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'.
The file was not found in a project.
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\vccorlib\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\dev\AutoMapper\src\AutoMapper\Mapper.cs.
The debugger could not locate the source file 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'.

And the option to locate the Mapper.cs file appears.

I tried to follow the example of this answer , but it did not help.

    
asked by anonymous 22.04.2015 / 21:22

1 answer

0

I got it right here, I was checking the error in the wrong place.

The problem was in my Pessoa class. I have ICollection . When you started it in the constructor, it worked perfectly.

public Pessoa()
        {
            Enderecos = new List<Endereco>();
        }
    
22.04.2015 / 22:12