Dust is going to be a big problem for anything with moving parts. Moon dust caused all kinds of havoc with the Apollo missions, getting all over every surface, causing respiratory problems, destroying equipment. Moon dust is incredibly sharp and abrasive, and because of UV bombardment it is also electrostatically charged, meaning that it wants to stick to everything and is almost impossible to get rid of.
It's also chemically active. After three days on the moon, Apollo 17 astronaut Harrison Schmidt had to throw away his geologic hammer because the handle had corroded away.
Hatches, seals, valves, bearings—any machinery that moves on the lunar surface will be subjected to dust damage. “Imagine sprinkling broken glass onto a seal,” said Gentry. “And then every time you cycle it, you sprinkle more glass. Sooner or later it’s going to leak.”
The dust on Mars is slightly better in that blowing in the wind wears off some of the sharp edges, but it is even more chemically active; the Red Planet is red because of iron oxide, and Mars certainly contains other mineral oxides and peroxides, which can cause chemical burns. The Pathfinder rover also found trace amounts of carcinogens like hexavalent chromium in the soil.
So any weapon you make with moving parts is going to have trouble in these environments.
There is an answer to this though: Metal Storm
A Metal Storm gun is made from multiple barrels, each packed with bullets that are fired electronically in a series.
There are no moving parts, no firing pin, there doesn't even need to be a trigger. Each barrel could be sealed right up until it's fired, and then once the gun is empty you replace the barrel with a full one. The rest of the gun could be made out of ceramics and other materials that resist corrosion and abrasion.
More on dust and the effects of dust
So there is no atmosphere or weather on the moon, so stuff shouldn't move around much, right?
Well no.
When the Apollo missions visited the moon, they left reflectors behind, and over the time since these reflectors have begun to degrade, which kind of baffled scientists; no wind to blow dust, and the degradation has worsened over time so it's not just dust that was thrown up when the astronauts left.
The degredation is also worse durring a full moon than it is when the face of the moon is in shadow.
Scientist now believe that when the solar radiation hits the dust on the moon it knocks off electrons, ionizes it, giving it a positive charge, and since like charges repeal, the dust particles push away from each other, with some lofting as far as tens of kilometers above the moon's surface.
When the sun sets the solar wind delivers electrons to the moon, deionizing the dust and causing it to fall, and sometimes lofting new dust as patches get negatively charged.
The further into the 14 Earth day "moon day" that you get, the more charged the dust will be, causing it to grow stickier and stickier.
So even without wind or people stirring it up the dust keeps moving around.
With people moving around, rockets landing and taking off, etc. it's going to be much worse.
Any new moon base will have to be planned out carefully, to keep launch facilities far away from science and living facilities.
There is also the problem of dust and electronics.
Dark lunar dust can prevent excess heat from radiating off of delicate electronic components, causing them to overheat.
The spray of debris caused by the Eagle's departing rocket motor led to the overheating and early failure of Apollo 11's Passive Seismic Experiment (the first major scientific experiment put on the moon by human hands).
Electrostatically charged dust can also potentially carry enough of a charge to shock unprotected electronics.
Toxicity and Health
Not much is known about how toxic dust is simply because no one has been exposed to it for very long.
It has been shown to at least cause respratory problems in astronauts in the short term, but long term effects are unknown and will need to be studied as we someday move back to the moon.
Vision is another area where dust will be a problem, since the dust is essentially microscopic jagged shards of glass, iron and unsatisfied chemical reactions. Scratched cornias are a potentially serious problem.
Mitigation
One interesting aspect of lunar dust is that microwaves can melt lunar soil in less time than it takes to boil a cup of tea. A future vehicle employed on the moon could therefore melt the dust into roads and launchpads. This would help reduce the amount of dust thrown up by people and vehicles on the lunar surface.
Alternating electrostatic fields in airlocks could be used to draw the dust away.