Giving advice is:
1. ...condescending. The subtext is, "I have moved beyond the problems you're having. Let me explain what to do to get to my level of functional excellence."
2. ...a hint that you don't want to hear about your friend's problems; that you either don't want to be bothered, or else that the existence of the problems makes you so uncomfortable that you want them to be solved and go away so you don't have to be confronted with them. In other words, it's a veiled rebuke to the sharer for an unwelcome act of sharing.
3. ...presumptuous, because it implies you think you understand the problem well enough to go about solving it. For example, if someone isn't getting along with their boss, suggesting that the person and their boss stay in more regular contact may misunderstand the degree of their animosity, or may ignore the fact that the person has already tried this, or may be contrary to the person's already preferred approach of finding a new job.
Sometimes, a person may really want your advice. In that case, one would suppose they would specifically ask for it. But if someone vents to you and they don't ask for your advice, then what do they want you to say? Why are they telling you? I see two related possibilities:
1. The person is confused about their experience and needs some grounding. Perhaps one contribution you could make in this case is to help articulate and identify feelings. If they tell you about failing a test, you can say "That must have been frustrating for you." You could also do some reflecting, such as "It sounds like you are disappointed because you want to be productive but you're not getting the tools you need." It is okay to make a guess because the person will probably correct you if you didn't get it right, and appreciate the attempt. The important thing to remember if you try this and they correct you is that they don't necessarily mean to contradict or discourage you. They are responding to your feedback in order to refine the picture of their internal state into one that feels right.
2. The person is feeling beat down by their experiences and needs a boost. In this case, the person wants an interaction that makes them feel loved and respected, since the problem they're dealing with is sapping self-confidence. It may seem pretty natural to them initiate an interaction out of which they want these things by bringing up what is on their minds and causing them to need this kind of interaction in the first place. It may be especially tempting in order to have the chance at an outcome where you, as their friend, have learned about the problem and yet still don't think the less of them for having it (or for having it and not having solved it yet). In this case, I would suggest caution around an attempt to make affirmative statements to boost self-esteem ("You can do it, you are the smartest person I know") because it risks sounding artificial. Just the act of listening and responding thoughtfully conveys respect and care.
In either of these cases, along with avoiding advice, also be careful with "why" questions about any feeling statement. For example, if someone says, "I hate so-and-so" and you ask, "Why?" then you are essentially questioning their choice to have that emotion, because you create the possibility that they could answer you and you might find the answer inadequate ("You're crying for THAT?") or maybe segue into advice ("Oh, you couldn't concentrate because you were up too late last night? Well, maybe you should go to bed earlier.") And anyway, most people don't immediately know why they feel a certain way. Perhaps exploring this is the reason they brought it up with you in the first place. So, your job is to give the support necessary so they can sort it out, not to be a detective or a professor.
I really think there should be some formal teaching on subjects like this.
 How to Talk So Kids Will Listen & Listen So Kids Will Talk