Replies: 3 comments
|
These are all compiler tricks with C#. There is nothing enforced at runtime. AutoMapper creates code at runtime that bypasses the compiler entirely. We could investigate raising an exception at configuration validation time, but that would involve us digging in to the compiler-emitted metadata (usually additional attributes on members), and I'm not sure it's worth the effort. |
|
Actually, in your case, if you validate your configuration, you'll get an error, regardless of |
|
I'm running into a similar issue when using collection marked with |
Uh oh!
There was an error while loading. Please reload this page.
C#11 / .NET 7 has a new feature that allows properties to be marked as required.
Documentation for it: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required
This is also enforced during JSON deserialization: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/required-properties
It seems that when using AutoMapper this isn't enforced though, and this code runs just fine:
It shouldn't be possible that
Addressis empty, ideally this would raise an exception when mapping.All reactions