C # coercion operator?

I got this test:

[Fact] public void EverythingIsMappedJustFine(){ new AutoMapperTask().Execute(); Mapper.AssertConfigurationIsValid(); } 

This raises a slightly strange exception:

Check 'Unit.Web.Bootstrap.AutoMapperFacts.EverythingIsMappedJustFine' failed:
System.InvalidOperationException: Undefined coercion operator
between the types "System.Void" and "System.Object".
in System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow (ExpressionType coercionType, expression expression, type convertToType)
...
in AutoMapper.DelegateFactory.CreateGet (MethodInfo method)

Unfortunately - I could not reproduce this on a smaller scale and I can not understand what exactly is happening.

What is a coercion operator?


This may be helpful. But I cannot extract and drown out the necessary information bits.

+4
source share
1 answer

I still don’t know what exactly is the coercion operator, but at least - I solved my problem with the found cause.

After some debugging, Automapper was able to reproduce the problem:

 namespace mappertest { using AutoMapper; using NUnit.Framework; [TestFixture] public class FooFacts { [Test] public void MapToFizz() { Mapper.Initialize(c => c.AddProfile(new FooProfile())); var foo = new Foo { Bar = "BarValue" }; var fooModel = Mapper.Map<Foo, FooModel>(foo); Assert.AreEqual("BarValue", fooModel.Bar); } } public class FooProfile : Profile { protected override void Configure() { CreateMap<Foo, FooModel>(); } } public class Foo { public string Bar { get; set; } public void Fizz() { } } public class FooModel { public string Bar { get; set; } public FizzModel Fizz { get; set; } } public class FizzModel { } } 

Quite simply, as it turns out, the source has a method called as a destination property.

+5
source

All Articles