Napoleon somehow did not have very much trouble doing just that back in the day.
But it's of course not limited to small arms distributed among the population. There are many more preparations done in advance, like rocks prepared to block roads if an explosive charge is detonated. Same with various bridges and railroad choke points. There's a large network of shelters and bunkers, kept in a good shape. Etc, etc.
The point is not that a huge army (like Hitler's in 1940) would not be able to overrun Swiss resistance. The point is that the cost of such an invasion would be prohibitively high. It serves as a good deterrent.
You proved my point. Doesn't really have to do with the gun owning population but to the unique geography of the country giving them a massive advantage.