The core of the paradox lies in a subtle mathematical mistake. The simple calculation of expected value isn't applicable in the way it's presented.
The Flaw: The Variables are Not the Same
The error is in the setup of the expected value calculation. Let the smaller amount be A. Your envelope X is a random variable, which can be either A or 2A. The amount in the other envelope, Y, depends on X. If X=A, then Y=2A. If X=2A, then Y=A. The calculation E(Y|X=x) = 1.25x is incorrect because the two 'X' values in the formula (2X and X/2) are conditioned on different underlying states of the world. The 'X' if you hold the smaller amount is not the same value as the 'X' if you hold the larger amount.
Resolution: Using a Proper Probability Distribution
A key resolution involves realizing that the amount of money, A, cannot be selected from a uniform probability distribution across all positive numbers (such a distribution does not exist). In any realistic scenario, there is a probability distribution p(a) for how the initial amount A was chosen. Once you define a proper prior distribution for A, you can use Bayesian reasoning. For a given observed amount X, you can calculate the posterior probability of whether you are holding A or 2A. This often leads to a conclusion where switching is not always the best strategy. For example, if you see an extremely large amount of money, it's more likely you're holding the 2A envelope.