Use Automapper exception?

Using mvc5 with an automaton, I follow:

In the controller:

  [HttpPost]
        public ActionResult LunchMenu_Create_Index(VmSysMenuCreate menu)
        {
            try
            {
                var domainMenu = Mapper.Map<VmSysMenuCreate, Menu>(menu);
            }

            catch (Exception ex)
            {
                return Content("Error msg");
            }

            return Content("Succes");
        }

Mapping:

  Mapper.CreateMap<VmSysMenuCreate, Menu>()
                .ForMember(c => c.Id, op => op.MapFrom(v => v.Id))
                .ForMember(c => c.MenuDate, op => op.ResolveUsing(data =>
                {
                    try
                    {
                        DateTime convertedDate = Convert.ToDateTime(data);
                        return convertedDate;
                    }
                    catch (Exception ex)
                    {

                        throw new Exception("Date not in correct format", ex);
                    }

                }));

By doing this, I was allowed to catch the automapper error when trying to match my objects, but this does not work as I expected.

How can I catch an error in the controller that is being thrown from automapper? If you have any questions, ask me. Thank you for the attention!

-1
source share
1 answer

Not sure, but you probably have the CLR Exceptions option released.

Select "Exceptions ..." in the "Debug" menu. (or press CTRL+ ALT+ E)

enter image description here

Thrown , , .

-1

Source: https://habr.com/ru/post/1531806/


All Articles