Use Mapperly instead

More often than not, AutoMapper causes more problems than it solves.

AutoMapper can be useful in a few simple scenarios, but it’s never a good idea to use it in a large codebase. Things can get out of hand quickly if people don’t fully understand what they’re doing or if its usage isn’t strictly moderated.

You should drop AutoMapper in favor of Mapperly. Or in simple cases, just write the mapping code manually — especially with the help of LLMs.

Source Generators Are Just Better

Mapperly is based on source generators, which means you can inspect and debug the generated mapping code. The code it generates typically looks like what you’d write by hand.

The more time you spend programming, the more you’ll dislike “magic”, and the more you’ll appreciate code that is expressive and straightforward. AutoMapper is full of magic. It’s reflection-based. Even if you try to step into the library code, chances are it won’t make much sense.

Nullability

Another issue with AutoMapper is that it doesn’t respect nullability. It will happily allow mapping from a non-nullable property to a nullable one — by design. Nullability is a chain of trust. Once a null value unintentionally makes its way into a non-nullable property, the entire chain breaks. A workaround is to use Automapper custom resolvers, but still, it only helps at runtime. In contrast, Mapperly will emit a message in this case (which you can configure as a warning, if needed) through its analyzer. It also provides other helpful diagnostics.

No Lock-In

Source-generator-based mapping libraries don’t tie you down. If you decide to stop using the library, you can simply drop it and keep the generated code as if you wrote it yourself. That’s not the case with libraries like AutoMapper.

Congrats, You Saved 50 Lines and Lost 2 Hours

Writing mapping code manually or using a source-generator-based library may result in more lines of code, but that’s not a problem at all. Fewer lines of code don’t necessarily mean your software is less complex. With AutoMapper, having less code obcures the mapping logic, making it harder to understand what’s actually happening.

Final Thoughts

With the rise of source-generator-based mapping libraries, I see no reason to use AutoMapper anymore, unless you’re stuck using a very old version of .NET.