I can give you a lesson in chemistry of the materials if you like.
Suffice to say that being a metal with high electrochemical activity, most magnesium alloys have a tendency to corrosion in certain situations.
Among the stuff that can result in really bad corrosion are:
salt solutions, including chlorides dissolved in freshwater
all mineral acids bar HF
anhydrous methanol
halogenated organic compounds (only at high temperature)
Generally speaking magnesium will develop a thing gray patina (passivation in old chemists' parlance) when exposed to atmospheric humidity or water sprays that protects the underlying metal but when moisture is trapped on the surface by dirt, that patina will be eroded very slowly due to the aforementioned electrochemical activity, leading to the most common form old magnesium rot. The presence of contaminants such as chlorides will accelerate the process.
Contant high air humidity (over 80%) will also speed up the corrosion process.
Your standard pro-grade chainsaw is usually treated to prevent magnesium rot, or at least to slow it down but there's no cure for poor material handling. Keeping the saw clean and storing it in a low humidity environment will help bunches.
Personally I am not a fan of magnesium repairs, especially in areas like felling dog and anti-vibe attachments, but some people here have attempted repairs.