Portrait Interaction Optimizer custom functions / plugins being upgraded produce an error when used at runtime


Portrait Interaction Optimizer custom functions were upgraded and deployed, but produced an error when used at runtime.
The error stack in the event log contained the following text:
Message:Host integration unexpected error AdditionalInfo:Failed to execute function
Exception has been thrown by the target of an invocation.   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at AIT.Portrait.Decisions.Engine.DecisionContext.get_Item(reference ctxRef, IEvaluationContext leafContext) in l:\AMC2000\DotNet\Decisions\AIT.Portrait.DecisionEngine\DecisionEngine.cs:line 1153
 HRESULT:0x8bd20001, Source:l:\AMC2000\DotNet\Decisions\AIT.Portrait.DecisionEngine\DecisionEngine.cs[get_Item](1171), Facility:0x1f4b, Type:2, Category:3, Severity:63, MachineName:XXXXX, Process:999, Thread:999, Time:hh:mm:ss.ms dd-mm-yyyy UTC, ActivityToken:XXXXX
 Data is the serialised LogMessage


This happens when you recompile the custom plugin code and set the 'Platform target' setting to be 'Any CPU'.
This causes a problem on native 64-bit servers as it then expects the code and the dependent Portrait DLLs to be x64- compliant.
Portrait Foundation is currently an x86 (32-bit) application, so this will not work.


UPDATED: March 31, 2017
Ensure that you 'Platform target' settings are only set to be 'x86'.
Recompile the plugins and redeploy them.
Your plugin code should not fail with the above error any more.