The last version of the Oilhead 5-speed gearbox (known as the M97, used from April 1996 until the R1150 versions came out) has a weakness in the input shaft which manifests itself as opaque brown gear oil when you're servicing a high-mileage bike. This comes from the drive gear on the input shaft rubbing against the rear bearing (which it normally does) to the extent that the two start to wear into each other (which is bad). These transmissions, which otherwise are the best of that entire series, can be identified by the last three letters of the gearbox code starting with E. The gearbox code is on the right side, behind the throttle body when the transmission is installed on the bike.
Take a look at the input shaft assembly. The spring is part of a shock damper that allows the gear to turn slightly relative to the shaft, to smooth out power pulses from the engine. If you look closely, though, there are two springs: there is a wavy washer at one end which allows a tiny bit of compression before the heavier main spring takes over. Although I have no opinion on this, it's been suggested that the weak initial movement allowed by the wavy washer is responsible for the wear, and some people shim the assembly to remove that movement.
The fundamental problem is that there isn't a lot of contact between the gear and the inner bearing race. All of the force of the spring (and the helical reaction of the gear itself) is borne by a surface about 1.5mm wide on the gear and bearing, which rotate against each other as the gear moves on the shaft. As that happens, the gear works its way into the bearing and in extreme cases the gear teeth start to rub on the outer bearing race.
The good news is that the replacement gears have a larger surface contacting the bearing. The original gears had a chamfer on the inside which took away nearly 40% of the available contact area. The replacement gears do not have that chamfer.
The bad news is you're not entirely out of the woods yet. Sometimes when the gear has started to eat into the bearing, you'll find that the bearing has spun on the shaft and is now loose. Fortunately the majority of that wear seems to happen on the bearing, so the new bearing might still be a properly tight fit. If not, you should replace the entire shaft assembly.
Provided you can get away with just replacing the gear, while BMW does not sell individual parts for the M97 input shaft the gear is the same as was used on the previous generation (M94) transmission, and that gear is available for about $245. You'll need a new bearing, too, and new seals, so the bill will be a bit over $350 in parts plus your mechanic's time. It's still way better than a new transmission, which costs roughly what the bike (with functioning transmission) is worth. Now you know why people part bikes out!
Replacing this isn't an easy job by any means as the transmission must be removed (about seven hours in all) and then it must be opened to overhaul the input shaft. Rebuilding the transmission should be done by someone who doesn't need instructions from me, but removing the transmission isn't all that hard and will save you a few hundred dollars. If you can manage that, the whole repair should be well under $1000, even if you have to ship it to someone.