When trying to set a property added in .Net 4.5 on a system which only has .Net 4.0 you get MissingMemberException
(https://msdn.microsoft.com/en-us/library/system.missingmemberexception(v=vs.110).aspx). However you can only catch this when using reflection, otherwise it is an uncatchable JIT exception. (Why is it not possible to catch MissingMethodException?)
So I changed my code from:
client.DeliveryFormat = SmtpDeliveryFormat.International;
to
var p = client.GetType().GetProperty("DeliveryFormat");
if(p!=null)
p.SetValue(client, SmtpDeliveryFormat.International);
However now I get a TypeLoadException
thrown instead about SmtpDeliveryFormat
because this enum was only added in 4.5 also.
How can I work around this second issue?