In statistical physics, the challenging combinatorial enumeration of the configurations of a system subject to hard constraints (microcanonical ensemble) is mapped to a mathematically easier calculation where the constraints are softened (canonical ensemble). However, the mapping is exact only when the size of the system is infinite and if the property of ensemble equivalence (EE), i.e. the asymptotic identity of canonical and microcanonical large deviations, holds. For finite systems, or when EE breaks down, statistical physics is currently believed to provide no answer to the combinatorial problem. In contrast with this expectation, here we establish exact relationships connecting conjugate ensembles in full generality, even for finite system size and when EE does not hold. We also show that in the thermodynamic limit the ensembles are directly related through the matrix of canonical (co)variances of the constraints, plus a correction term that survives only if this matrix has an infinite number of finite eigenvalues. These new relationships restore the possibility of enumerating microcanonical configurations via canonical probabilities, thus reconnecting statistical physics and combinatorics in realms where they were believed to be no longer in mutual correspondence.