Did you see the value in the box before deciding whether to switch?
If you did not see it: You are calculating the expectation wrong. You said there are two events, the second box containing $2v$ or $v/2$. But this conditions on a particular $v$ being in the first box. You did not see what's in the first box, so this is inadmissible. The correct pair of events is that either the second box contains $2n$ and the first box contains $n$, or else the second box contains $n$ and the first contains $2n$, with probability $0.5$ for each event. (Of course you are therefore indifferent to switching.)
If you did see it: You are calculating the expectation wrong. Conditioned on opening the box and seeing $v$, there is a posterior probability that the other box contains $2v$ and a posterior probability that the other box contains $v/2$. These probabilities are determined via a Bayesian update from their prior probabilities, updating on the event that the first box contains $v$.
In general these probabilities will not be $0.5$, but we cannot compute them because you did not tell us a prior distribution on the values in the boxes. Without a prior, the posterior is not defined and you cannot calculate the expected value of switching.
For example, if you are told $n = 50$ in advance, i.e. guaranteed that one box contains $50$ and the other $100$, then of course you should switch if the first box contains $50$ but should not switch if the first box contains $100$.
If you are told that $n$ is drawn uniformly from $[0,N]$, then you should not switch if you see $v > N$ because you must already have the larger box. Etc.