I suppose it's worth noting that I'm very transparent as a DM. I roll dice in the open, I tell players the AC of monsters before they make the attack roll, I give them indications of what their good saves might be, and once someone would encounter a resistance or immunity, I try to give them some indication of it's existence before they commit to an attack. Further, if it's a monster I feel they may have heard of, I don't mind giving them a die roll to have heard of it.
As an example of this in practice, I once had a Bard player try to Command a Gnoll. Now Command is language-dependent, and Gnolls only speak Gnoll. So I asked him to make an Intelligence check to realize that fact (I think I used History for this (knowledge of Gnolls), or it may have been Arcana (knowledge of how the spell works), it's been awhile). He fails, so I ask if he knows Gnoll. He doesn't, so the spell fails to work.
In this instance, I saw the mistake, and decided to see if the character was savvier than the player.
Sometimes, it's unavoidable that the players find things out the hard way. And that's fine, so long as it doesn't come up often. Another thing I need to point out is that I really don't think punishing players for a specialization is fun, so I rarely do it. If the Wizard Dark Schneider only knows spells that deal Fire or Lightning damage, I'm not going to have him run into a custom homebrew Purple Dragon that's immune to both elements without him seeing the thing coming a mile away. If a player wants to build around a theme, like Elsa the Ice Sorceress, I'll have a chat with the player about how likely it is for the campaign to veer into the northlands where ice resistance is common, and make sure they keep that in mind as they gain new spells.
One of the worst experiences I ever had in older D&D was the Ranger. The subject of choosing a Ranger's favored enemy was such a drag. I could only guess at how prevalent a monster type would be at game start, so I'd steer them towards common choices. And I'd always have to double check the monsters in an adventure to see if there was a chance for the Ranger to shine. More than once, I'd give the Ranger a chance to switch to a new favored foe, after a particularly harrowing encounter.
So yeah, if my attempts to make damage types more relevant in the game go south, believe me, I'll stop before it becomes problematic.