Bugfix to work wit .NET 4.5 (prevent exception "Operation could destabalize the Runtime") - thiscode/CsvHelper GitHub Wiki
Using the Method "ConvertUsing" will fail under .NET 4.5. The exception "Operation could destabilize the Runtime" will be thrown. The solution is to convert the convert the returned value from the expression into the expected type:
//Before:
var exp = Expression.Invoke( propertyMap.ConvertUsingValue, Expression.Constant( this ) );
bindings.Add(Expression.Bind(propertyMap.PropertyValue, exp));
//Fixed:
Expression exp = Expression.Invoke( propertyMap.ConvertUsingValue, Expression.Constant( this ) );
exp = Expression.Convert(exp, propertyMap.PropertyValue.PropertyType);
bindings.Add(Expression.Bind(propertyMap.PropertyValue, exp));