Unify with PInvoke branch.