An eigenmode projection technique (EPT) is developed and employed to solve problems of electromagnetic resonance in closed cavities and scattering from discontinuities in guided-wave structures. The EPT invokes the eigenmodes of a canonical predefined cavity in the solution procedure and uses the expansion of these eigenmodes to solve Maxwell's equations, in conjunction with a convenient choice of port boundary conditions. For closed cavities, resonance frequencies of arbitrary-shaped cavities are accurately determined with a robust and efficient separation method of spurious modes. For waveguide scattering problems, the EPT is combined with the generalized scattering matrix approach to solve problems involving waveguide discontinuities with arbitrary dielectric profiles. Convergence studies show stable solutions for a relatively small number of expansion modes, and the proposed method shows great robustness over conventional solvers in analyzing electromagnetic problems with inhomogeneous materials.