One of the best examples of this is Marion Zimmer Bradley's Darkover novels, where magic makes ranged weapons (and weapons of mass destruction) possible, but everyone (in the aftermath of several very destructive wars) has agreed not to use it like that, because it makes war just too damned lethal.
There was a long-standing loony theory that Matrim Cauthon in Robert Jordan's The Wheel of Time would invent guns at some point; this was recently confirmed when, in the 11th book, he used bombs against the Seanchan, and now he and Aludra are working on designing a cannon. Interestingly, a significant portion of the fanbase was seriously averse to the idea of guns, with some even saying that firearms would significantly lessen their enjoyment of the series. It has also been suggested that one of the reasons the Illuminators are so secretive is because they know the potential of gunpowder, and don't want it to be used as a weapon. However, given the premise of the series, it's possible that guns have been invented and forgotten hundreds of times.
There's also the fact that for hundreds of years in the current Age female Channelers have used distance attacks with the One Power. Aes Sedai are forbidden to use the Power as a weapon, true, but that doesn't stop most other groups of female channelers in the world, or Aes Sedai acting in self-defense or against Shadowspawn, which is the exception to the rule. Also Rand's Asha'man practice using the Power as a weapon, and firing it at targets from a distance, as part of their intense training. And the Power is arguably more destructive than any gun, especially when used by someone who's very strong and skilled.
It's actually more or less stated that the gunslingers are direct descendants of not just your standard fantasy knight equivalents, but All-World's equivalent of King Arthur and his Knights of the Round Table. The metal in Roland's guns is supposedly from Arthur Eld's melted-down sword. That makes it easy to "keep a straight face."
Also All-World, Roland world, was once a futuristic world not that different from ours, but there was some type of apocalyptic war went down and now it's "After the End" besides other guns do show up from time it's just not many are left any more, and of those not many work (thought some new ones do come in from other levels of tower from time to time.)
Guns are rare simply because no one knows how to make or fix anything complex. The world has moved on.
Also averted in another, related, Stephen King novel, The Eyes of The Dragon. The mediaeval-style kingdom of Delain has gunpowder and cannon, though they are high-tech enough to be rare, but King Roland killed the eponymous dragon with a bow and arrow, which was was a key point in the climax of the book.
A science fiction version of this in the early Gor series books. The author (John Norman) wanted the characters using primitive weapons only, so he had the alien Priest-Kings prohibit the inhabitants of the planet Gor from possessing firearms. Anyone who violated the rule suffered the "Flame Death" (inflicted Spontaneous Combustion). In a later book, their enemies, the Kurii, "got around this" by giving their human collaborators powerful air rifles. In real history, such weapons were used by Austrian troops in the Napoleonic Wars, and Lewis & Clark took one on their expedition across North America. The major advantage in the Kurii's case was that the air rifles had greater range and accuracy than the common bows and crossbows the Priest Kings permitted, but unlike gunpowder weapons were nearly silent. Which actually was the main reason the Austrians and Lewis & Clark used them- the early 19th Century version of a suppressed weapon.
There's an aversion in the first of the Kai Lung series of stories, where a bandit is shown armed with a handgun as a way of calling attention to the stories being about an extremely fictionalized Ancient China.
In Joel Rosenberg's Guardians of the Flame series, the heroes, who are all modern-day college students, introduce gunpowder technology to the fantasy world they've been teleported to. This prompts the natives to develop a Magitek version involving superheated steam and a spell that prevents it from expanding until the proper conditions are introduced by the pull of a trigger.
In Diana Wynne Jones's Dalemark Quartet, guns exist, but they're rare and expensive because few craftsmen have the skill to make them (the state of the art is roughly equivalent to our 18th century). South Dalemark armour is specifically designed with "exaggerated curves" to deflect bullets.
L. E. Modesitt's Recluce series. Guns do work and some people know how to make them, but they're considered impractical because chaos mages can cause gunpowder to ignite from a distance, killing the would-be gunslinger. This is subverted both early on and late in the timeline. The "angels" from another universe in Fall of Angels possess slug-throwers, rifles, and lasers, but those run out of ammo, energy, or break. In the later books, Hamor perfects a manufacturing process that allows bullets and cannon shell to be virtually immune to chaos magic. Other modern weapons make their appearance: anti-personnel mines, rocket guns, and even Frickin' Laser Beams on a Kill Sat when sunlight focused by a lens (and Order) carried on a hot air balloon destroys Fairhaven
The Corean Chronicles, on the other hand, did feature firearms. The prequel trilogy stated that the Cursors tried to ban all rifles used by their subjects other than one standardized caliber - which didn't have the stopping power needed to hurt a Cursor unless the shooter was very lucky. This was to prevent the lower classes from developing large caliber rifles, and any kind of cannon, so that they couldn't make a serious effort at rebelling. This effort fell apart shortly before their empire did (for totally unrelated reasons).
In the Coldfire Trilogy, guns exist but generally are not used, as the psychological impact of the fae (which alters the real world based on the subconscious thoughts and fears of people — sort of, see its page for a better explanation) mean they have a nasty habit of not working properly, they're rarely used in combat.
The Monarchies of God pentalogy avoids this one, with primitive guns and swords coexisting seamlessly. The guns are only able to be fired twice a minute (three times if the soldier is particularly well trained) and have a limited range, so arrows of various sorts are still useful, and traditional cavalry and infantry are the bulk of forces.
Steven Erikson's Malazan Book of the Fallen does not have guns, but it does have dynamite-like munitions. These are quite nasty: In Reapers Gale, a few Malazan soldiers armed with munitions manage to fight off and seriously injure several dragons, including Silchas Ruin, a BadassAscendant.
These munitions are still tightly controlled since only the Morath warrior clans are able to manufacture them on a large scale and are picky on who they trade them to. When a Malazan army recruits an alchemist to make their own versions, the final products are very effective but are essentially biological and chemical weapons rather than pure explosives.
The Morath also keep the most powerful versions for their own use. While the standard munitions are extremely lethal, when an army's sappers get their hands on some stolen advanced munitions, they end up blowing an opposing army to smithereens in the opening action of a battle with a single salvo. It's no wonder that the Morath keep such tight control over these weapons.
In Roger Zelazny's The Chronicles of Amber series; gunpowder just doesn't work in Amber because the laws of physics are different there. And then subverted in The Guns of Avalon, when Corwin discovers a substance in a nearby Shadow world that can combust in Amber — and immediately brings mass quantities of the powder to Earth and has it made into ammunition, arming his troops with modern automatic weapons.
Played with in one of the Dragaera books. It is revealed in Orca that, long ago, soldiers used weapons along the lines of magical flintlocks — they look like sticks, are one-shot, and are just as likely to amputate the fingers of the user as kill the enemy. Later, at the time of the Khaavren series, "flashstones" are used, which are sort of like a combination grenade/gun; they only allow two shots at best, and blow anyone hit by them to pieces. Thanks to advances in Magitek, though, by the time of the Taltos series, there is no need for anything like this, as you can simply draw on the Orb's power to attack an enemy.
In a book set later in the series' timeline it's mentioned that flashstones were discontinued after a sorcerer developed a counterspell that could remote detonate an opponent's stone (usually with fatal consequences for the opponent). This counterspell was area effect, and in its first public casting was applied to the entire opposing side at once. Ouch.
The absence of guns is probably more a case of Brust's personal fondness for swashbuckling over shoot-em-ups. Note that it's not just firearms that are excluded; even archery is apparently not much practiced in the Dragaeran Empire, as Vlad doesn't even recognize that the bows ("javelin-throwers") wielded against his unit in Dragon are weapons until they're explained to him. The fact nobody can believe Vlad could bag wild game without sorcery suggests that arrows aren't used in hunting either.
Averted in Barbara Hambly's The Windrose Chronicles. Handguns are not uncommon, and anyone expecting to go up against wizards with one has magic-nullifying runes carved on theirs, so it doesn't end up exploding in their hand.
In the Harry Potter series of books, guns exist in the Muggle world; for example, the Muggle news claims escaped criminal Sirius is carrying one (he really has a wand, of course). While the Ministry of Magic has a department to study Muggle artifacts, no wizard (or even squib) is ever seen using or even carrying a gun. This may have something to do with it's being set in 1990s Britain, where guns are far from commonplace even amongst Muggles.
And, indeed, wizards don't even appear to know what guns are, in spite of the many wars that one must assume they noticed. The Daily Prophet has to explain them as "a kind of metal wand that muggles use to kill each other." Kingsley Shacklebolt also makes a comment to Arthur Weasley, incorrectly referring to them as "firelegs" instead of "firearms," implying that they're completely off the ordinary wizards' radar.
The Death Eaters despise Muggles, it therefore follows they'd not consider Muggle technology remotely worth using. The "good guy" wizards, though they do kill, aren't seen using Avada Kedavra; combined with the lack of interest in Muggle technology among most wizards in general it figures they wouldn't be interested in firearms.
Word of God is that the magical higher-ups do understand guns and other Muggle weapons, the Masquerade is in place because of it. A Muggle with a shotgun will usually beat a wizard with a wand; if it ever came to open war the magical world wouldn't stand a chance.
Subverted heavily in Everworld. 5 modern teenagers find themselves in an Alternate Universe full of ancient gods and medieval technology. There are several references throughout the books to situations where artillery or handguns would be very useful.At one point, they trade a modern chemistry textbook to the Coo-Hatch in exchange for attaching their metal that can cut through anything to one of the main characters swiss army knife. The Coo-Hatch use the technology to build a primitive cannon, which is used at the battle of Mount Olympus. And of course, later in the series, Senna uses her powers to bring in a small, heavily-armed group of followers from our universe, and they conquer several cities and kill a minor god, thus threatening all of Everworld.
Garth Nix's Old Kingdom trilogy features a dichotomy between the magical Old Kingdom and the modern (early 20th century) world, Ancelstierre, separated by a wall. The closer one gets to the wall, the more modern technology falls apart — machine-made paper crumbles, and firearms stop working. However, the border guards use guns to blow away zombie baddies who try to cross into the modern world from the Old Kingdom. Provided the wind doesn't blow from the north. Apparently whatever anti-technology aura the Old Kingdom possesses is blown around by the wind. The guards also carry magic swords as backup (unofficially), and some are even mages.
David Weber's Bahzell series doesn't have guns, until a short novella has Wencit use magic to summon help from beyond. Bringing a pair of US Army troops in a Stryker gives people who see it ideas. And averted in his Safehold series where culturally the whole planet is in stasis, but cannons of varying sizes are commonplace, and then the spirit of a long dead Interstellar naval officer arrives in a cyborg body and teaches them about rifling.
A Song of Ice and Fire has no guns, although the Westerosi do seem to have invented a kind of ersatz napalm in the form of wildfire.
In Robert Lynn Asprin's Myth Adventures series has dimension-hopping, high technology, and plenty of warfare, but no guns. The stereotypical mobsters carry crossbows in their violin cases, and others use magical wands. There are references to firearms, but for "demons" it's not a best option: in a random dimension one clearly has better chances to get either crude bolts or Ley Line than ammo for the specific gun.
Averted in the Heirs of Alexandria books by Mercedes Lackey, Eric Flint, and others. They're set in an alternate 1500s, and guns are certainly present, and about as effective as they were in our 1500s.
David Drake and Eric Flint avert it again in their Belisarius series, where the eponymous general knows of guns and actively tries to arm his troops with them. But attempts to produce them en masse when your industrial base is basically just a bunch of haughty Byzantine artisans (who do not know and do not want to know anything about, say, standardization) usually give interesting results. Pistols and rifles yes but both sides use cannon, rockets and grenades aplenty.
Averted in Death of the Necromancer by Martha Wells. Guns exist side-by-side with knights, swordplay, and magic (including that of the eponymous necromancer). The prequel, "The Element of Fire," has a quasi-Elizabethan setting, and the protagonist uses a wheel-lock gun in the first chapter.
Averted in the Mistborn series, as you find out in the third book that gunpowder does exist, but the Lord Ruler suppressed knowledge of it, since it could allow for the creation of large rebellious armies that needed little-to-no training.
It is then averted in the Alloy of Law, which is a fantasy equivalent of the wild west: aluminum guns and bullets that can't be affected by magic, speciality guns with entirely internal triggers and safeties that can only work for certain types of mistings, new combat counters for mistings that have arisen in the gun age, and even speciality anti-misting bullets that exploit those anti-gun counters.
Averted in The Last Unicorn where guns are mentioned though not used. The book itself is a bit of of an Anachronism Stew, because John Henry is mentioned as well.
Literal Fantasy Gun Control is in Lord Kalvan of Otherwhen by H. Beam Piper. The priests of Styphon control the knowledge and production of "fireseed" (aka, gunpowder) to their political and economic advantage: supply fireseed to one side in a war and not the other, and the war is effectively over, so they have exercise something between extreme influence and out-right control of the entire world. Unfortunately for them, Calvin Morrison accidentally hitch-hikes from our world to theirs due to a ParaTime accident, and has full knowledge of the formula and method of production of a more powerful form than Styphon's House.
In the alternate Earth of The Case of the Toxic Spell Dump, mundane firearms (called "mechanicals", to distinguish them from wands) do exist, but in a far more primitive state. Justified in that wild elemental spirits are evidently attracted to explosives, and would cause the weapon to blow up if a gun used powder of greater than medieval-era purity.
Averted in various "fantasy-of-manners" series, which include firearms as a natural part of their post-Renaissance motif.
Averted in Artamon's Tears by Sarah Ash, where gun are used quite liberally by the people of Tielen, which allows then to conquer the rest of the world, which does have Fantasy Gun Control.
Averted in the Queen's Thief series. While the countries in the series are Fantasy Counterpart Culture versions of Ancient Greece and Persia, the setting has some late Medieval elements, including flintlock weapons.
They are, however, heavily controlled. Attolia, for example, has some handguns on hand for use by the Royal Guard, but no one has an assigned handgun; when the situation calls for a gun, the soldiers report to the armory and collect the weapon, then turn it in when they go off duty.
Averted, and then re-established in the Discworld book Men at Arms. A gun is invented in Ankh-Morpork, and it takes control of whoever wields it and turns them into unstoppable killers. When the arcane thing is finally defeated, it is buried forever with a fallen guardsman so he can have a peerless weapon in the afterlife.
That said, they do have black powder, cannons, what have you. The issue appears to be mainly that when they're as portable as the "gonne", the amount of magic in the air even in mundane parts of the Disc makes the little voice in your head telling you how powerful this tiny killing machine makes you move into the weapon itself.
The "gonne" itself practices Fantasy Gun Control as it insists that no copies should be made and kills an artisan who tries to duplicate it.
Note that only the Agatean Empire has cannons, and it has little contact with the other Discworld countries. Also, its cannons are still on an early stage, exploding as often as not.
In the Liavek books, guns exist, but it's possible to use magic to keep them from working within an enclosed space.
Guns and explosives exist in the universe of the Soldier Son trilogy. In this universe, iron kills magic, making the Gernians' guns a very effective weapon against the plainsman mages.
Last Dragon has the soldiers of Proliux using arquebuses in their conquest of the north.
In John Ringo's Council Wars series, Mother, the AI that runs Earth, actively suppresses energy releases over a certain low threshold (except in very specified circumstances). Before the war breaks out this was just a matter of public safety, and no one really cared because their Clarkes Law tech rendered such limits irrelevant. Following the outbreak of war, and the resulting loss of the supertech to most of the population, it means that not only can they not use firearms, they can't use most forms of internal combustion engines or power production either.
Averted in Septimus Heap, where a gun made out of silver plays a major role in the first and third book.
In the first two books of Arcia Chronicles, guns and gunpowder raise no eyebrows (even though they are still too expensive for everyone but the nobles), but after the Time Skip, The Church finds a magic to remotely detonate all gunpowder in the vicinity, putting this trope into full effect.
Guns aren't specifically mentioned in Pamela Dean's Secret Country books, but high tech items you bring from the earth dimension tend to turn into their medieval equivalents in the Secret Country, e.g. a flashlight becomes a lantern, and a digital watch becomes its 15th century equivalent. One presumes that if you brought a gun it'd turn into, say, a bow & arrows.
Averted in the Lord Darcy stories by Randall Garrett. Though the world is very much a 'magic is the science' environment, guns are known and commonly used. Clearly seen in ''The Eyes Have It''.
Averted in Tales of the Branion Realm only in that naval ships are mentioned to have cannon, in two books set 250 years apart — you'd think that the technology would have percolated onto land by that point, but it hasn't. On the other hand, Seer Archers with the prophetic ability to See where their arrows will land are more accurate than any gun of the period could possibly be.
Obliquely referenced in The Lord of the Rings. Saruman's army uses blasting powder to breach the wall at Helm's Deep, and Orcs and Goblins are said to delight in explosions and other such mechanisms.
Averted and Lampshaded in Rune Breaker , Ere. Two characters use rifles and an ancient wizard complains bitterly about guns and grenades in the hands of non-wizards.
The Chathrand Voyages is a high-seas fantasy epic that quite thoroughly averts this one; all naval ships seen in the books (including the eponymous Chathrand) carry a full complement of cannon as their primary weapons regardless of national origin. Personal firearms exist but are still largely unknown; Sandor Ott, consumate Magnificent Bastard and Badass Grandpa that he is, has managed to get his hands on a pistol, however, and makes plain his belief that they'll be in common use in a century or so.
In V. Zykov's Way Home series of novels, gunpowder has been invented long ago. The invention was forgotten as an Area of Effect gunpowder-exploding spell was developed, rendering all firearms (personal to vehicular) moot. Averted later as the protagonists encounter unidentified ships carrying cannons and a ship-ranged counterspell, preventing mages from both detonating the ammo chamber and from destroying loaded cannons.
In V. Zykov's War for Survival series of novels, a whole city is transposed into a Magical Land. The humans liberally use firearms from the city's police and army compounds to wage war both against the world's inhabitants and in the city. As firearms are either underpowered or downright useless against some opponents, the city dwellers begin to resort to the arcane and divine magic which has awakened in some of them.
Averted and deconstructed in the Non Compos Mentis series of novels by Yuriy Ivanovich:
Flor is an explosive compound placed similarly to plastic explosives and triggered by any incendiary spell.
Dragons use solid fuel pills to enhance their fire-breathing ability by chewing the pills and mixing the resulting powder with their naturally flammable saliva into an equivalent of napalm. The pills themselves make for a sufficiently powerful explosive, used e.g. to take out a warehouse by exploding the fuel pill crates.
Among surviving ancient Precursor artifacts the most numerous would be the "litanra". Similar to a crossbow in appearance, every litanra uses a clip housing small energy balls for ammo, and features single-shot and burst fire modes. Another artifact recharges empty clips within minutes, apparently using ambient background magic. Litanra charges explode on hit and pass magic shields. Without a litanra, charges can be simply ejected from the clip, flung around with telekinesis spells and triggered by incendiary spells.
Litanra charges are especially nasty due to both the unexplained principle of burst shots being exponentially more powerful than single shots and the invention of a spell to reflect litanra shots while discharging them as hurrican supercells.
The Precursors have installed upscaled stationary litanras on a strategic location to allow long-range bombardment of almost the entire continent.
Deconstructed in the Father of Emperors series of novels by Yuriy Ivanovich: gunpowder works in the Magical Land the protagonists find themselves in, and they find historical evidence of firearms invented and then forgotten.
Centuries ago, a level 20 mage had approached a cannon-armed castle in the guise of a fleeting peasant and had cast the "solid air" spell inside the cannon barrels right before the besiegers entered cannon range. Attempts to fire the cannons caused critical failures, the castle was conquered and razed.
The protagonists loose a ship to the same tactic. Later they sink the hostile mages' vessel by ordering one allied mage to protect one cannon from being tampered with during the battle.
Another human from Earth made a career as a backwater Sanier kingdom's chancellor and introduced, among other things, artillery and riflemen companies to the army. The Sanier kingdom proceeds to curb-stomp the neighbors' armies and to cut bloody swaths into knight armies until the protagonists intervene.
An army detachment from Sanier is attacked by a "stone anaconda" guardian golem. As the golem ravages the infantry, the artillery opens fire on it regardless of "friendly fire".
Level 44 mages can cast a gunpowder detonation spell at about 50 meters, level 71 mages at about 5 kilometers of range. A mage at a level above 71 breaks the siege of the Vaderlon city and curb-stomps the above-mentioned Sanierian artillery and riflemen, complete with exploding ammo carts and infantry reduced to bloody bits.
In , Magic is Life, while Technology is Death. E.g., a mage shapes a wooden chair from living wood, while technology kills the tree to make the chair. The Magocracy strictly enforces this rule, so the few rebel technologists hide in remote areas, their technology mostly stuck in the Dark Ages.
In Robin McKinley's The Blue Sword, the local magic, called kelar, can cause firearms to jam or explode en masse, which was a big part of how the desert nomads known as the Damarians held the modern Homelanders at bay. Also seen in the story, when a group of Homeland soldiers leave their guns behind when marching out to fight with the Damarians against a mutual enemy.
Zigzagged in Dragonlance, where guns do exist and can be made quite easily. The problem is, these guns have been invented by the minoi, or "tinker gnomes", whose racial hat is Bungling Inventor. As a consequence, even beyond the fact that they are a peaceful people who have little inherent use for weapons in the first place, their guns tend to be ridiculously overcomplicated, heavy, inaccurate and prone to exploding. Furthermore, they can't sell these weapons to any other race (since "Gnomish invention" is interchangeable with "dangerous and unreliable piece of junk"), and no other race is inclined to develop them, since science in general has become regarded as the province of fools, imbeciles and lunatics, thanks to the minoi.
In one Dragonlance short story (Jeff Grubb's "Boom"), an unusually bright gnome actually discovers atomic fission weaponry. The leaders of the gnome immediately take his notes, lock them away, and exile him. He then turns to the dragonarmies of Takhisis; the wing commander refuses to countenance the idea of such a weapon (partly because it is far too impractical to use, mostly because the weapon is far too horrifically destructive) and sends him into slavery, covering up the weapon's existence forever.