Topological obstructions in Lagrangian field theories, with an application to 3D Chern-Simons gauge theory