Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange mapping behaviour from String to Boolean

By mistake, someone from my project wrote in the automapper profile the following sentence:

Mapper.CreateMap<Appointment, AppointmentModel>()
    .ForMember(x => x.DeclineStart, o => o.MapFrom(x => x.DeclineStart.ToString()))

Where DeclineStart is the property of the entity and the model classes.

public class Appointment
{
   public bool DeclineStart { get; set; }
}

public class AppointmentModel
{
   public bool DeclineStart { get; set; }
}

I know that in this case it is not necessary to create any mapping rules for this property.

To my surprise this mapping (from String to Boolean) is working.

But when we have published our application on Azure cloud service, this code become to throw the AutoMapperMappingException which shows that:

Missing type map configuration or unsupported mapping.
Mapping types:String -> Boolean (System.String -> System.Boolean)
Destination path: AppointmentModel.DeclineStartBackfill.DeclineStartBackfill
Source value:False

How it's possible that the same code is working locally, but isn't working on Azure?

Thanks in advance!


Azure machine configuration: Windows Server 2012 R2 / .NET Framework 4.5.1

Local machine configuration: Windows 7 / .NET Framework 4.5.2

Automapper version: 3.1.0

like image 762
Artyom Pranovich Avatar asked Jul 03 '26 00:07

Artyom Pranovich


1 Answers

Are all of your AutoMapper assemblies getting deployed, including the AutoMapper.Net4.dll assembly? That additional assembly has extensions available in .NET 4 that aren't available elsewhere, including type converters.

You have two options: manually reference something inside of the .NET4.dll assembly:

public static class LinkerHelper {
    public static object BecauseAzureDeploymentsAreDumb() {
        var foo = typeof(HashSetMapper);
        return foo;
    }
}

Or upgrade to the latest beta version of AutoMapper, where I've combined the platform-specific assemblies.

like image 178
Jimmy Bogard Avatar answered Jul 05 '26 15:07

Jimmy Bogard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!