Marginal costs MC is defined as $MC=\frac{dC}{dq}$. Taking into account that $C=wL+rK$,
$$MC=\frac{dC}{dq}=w\frac{dL}{dq}+r\frac{dK}{dq}$$
Recall that marginal product of labor $MP_{L}=\frac{\partial q}{\partial L}$ and marginal product of capital $MP_{K}=\frac{\partial q}{\partial K}$.
Question: is the following correct
$$\frac{dL}{dq}=1/\frac{\partial q}{\partial L},\;\frac{dK}{dq}=1/\frac{\partial q}{\partial K}$$
which implies
$$MC=w\frac{1}{MP_{L}}+r\frac{1}{MP_{K}}$$
If no, then no need to read further.
If yes, then, consider profit maximization of a firm.
$$\max_{L,K}pq\left(L,K\right)-wL-rK$$
FOC:
$$\begin{cases}pMP_{L}=w\\pMP_{K}=r\end{cases}\Rightarrow\begin{cases}MP_{L}=\frac{w}{p}\\MP_{K}=\frac{r}{p}\end{cases}$$
Therefore,
$$MC=w\frac{1}{MP_{L}}+r\frac{1}{MP_{K}}=w\frac{1}{w/p}+r\frac{1}{r/p}=p+p=2p$$
The result is wrong for sure. I wonder, at what step of derivation I made a mistake?