What are the harmonic rules that serve as the foundation of a solo? For example, notes of triads serve as the foundation for voices and arpeggios, with an occasional non-chord tone. Harmonic function serves as the foundation for chord progressions.
However, most solos I've come across seem to ignore the rules of chords, note intervals, range, and sometimes even keys. Additionally, the composition of solos seems to change depending on which musical genre you're in.
I don't know which ideas I should start with when writing solos. Other than fiddling around my keyboard and hope that I get lucky with the notes, is there a better alternative?
Edit 1: Aside from obvious ranges of an instrument, are there any limitations when writing for solos?
Also, what happens if I attempt to transpose a song and pushed the notes of the solo out of the instrument's range? How do I rewrite the solo section without changing the underlying "message" of the solo, since I can no longer rely on the inversion techniques for chord-based instruments?