In bringing my project's AutoMapper version up from 3.1.1 to current 10.0 the last couple of days I had to add in AutoMapper.Data because I use it to map IDataRecord to a DTO and that feature was removed from AutoMapper with version 4.0. That code now looks like this (obfuscating some names here):
static AutoMapperConfig()
{
Config = new MapperConfiguration(cfg =>
{
cfg.AddProfile<ProjectAProfile>();
cfg.AddProfile<ProjectBProfile>();
// Some methods use AutoMapper to map from an IDataReader (db result) into a DTO
cfg.AddDataReaderMapping();
cfg.CreateMap<IDataRecord, Models.GmlResult>();
});
}
That worked fine as I upgraded through each of the major versions of AutoMapper and AutoMapper.Data, until I got to AM version 10.0. Now the "AddDataReaderMapping" call appears to be throwing an exception:
---- System.TypeInitializationException : The type initializer for 'Mappings.AutoMapperConfig' threw an exception. -------- System.InvalidOperationException : MSIL instruction is invalid or index is out of bounds.
I tried adding an explicit "false" as a parameter in the call, no change. If I remove that call entirely, leaving only the CreateMap after it, my tests pass. This is acceptable, but I'm a bit nervous as to what that call did and why it doesn't seem to be needed anymore, and why it's throwing an error/what I did wrong. It had been working fine up until this point.
The config is inside of a static class that I earlier was using to actually Initialize the mapper, but now it's just holding this configuration, which is getting invoked anytime a new Mapper instance is created elsewhere.