Where does $xe^x$ solution come from when the characteristic polynomial is square? When solving the differential equation $y'' + ay' + by = 0$ (with constant, real coefficients $a$ and $b$, although they could be complex if you like), you do it by setting up the characteristic equation $r^2 + ar + b = 0$, finding its solutions $r_1, r_2$, and then the general solution to this equation is $Ce^{r_1x} + De^{r_2x}$. This works both when the solutions are real and when they are complex.
However, when we have a double root $r_1 = r_2$, we get a different general solution, namely $Ce^{r_1x} + Dxe^{r_1x}$. I have no trouble seing that this is indeed a solution, and intuitive reasoning on degrees of freedom dictates that we must have a linear combination of two terms in our general solution, while $e^{r_1x}$ and $e^{r_2x}$ are the same. So the fact that there is a second term of some other form is not surprising.
I have, however, yet to see a "natural" explanation of this $xe^{r_1x}$ term. If one were developing the theory from scratch, how would one find this solution (other than blind luck)? If I wanted to teach ODE's to a class of students "the right way", i.e. with good explanations and motivations for everything (as opposed to just pulling out ready-made solutions like what was done to me when I was learning this exact thing), how would I motivate even considering a term like $xe^{r_1x}$ (other than "Well, exponentials aren't quite cutting it, but this is kindof like an exponential, right? Let's try it.")? And is there a way of solving the general differential equation that does not involve splitting into cases depending on whether the characteristic polynomial is a square?

The simple direct approach gives the solution $xe^x$ without much hassle. Let the equation be $$y''-2y'+y=0$$ and let $z=y'-y$ so that the equation can be written as $$z'-z=0$$ The above equation on multiplying with $e^{-x} $ gives $$(ze^{-x}) '=0$$ or $$ze^{-x} =c_1$$ so that $$y' - y=z=c_1e^x$$ Again multiplying by $e^{-x} $ gives us $$(ye^{-x}) '=c_1$$ so that $$ye^{-x} =c_1x+c_2$$ or $$y=c_1xe^x+c_2e^x$$
