It’s the wp_nav_menu() call on the template that’s responsible for outputting the menu you’re trying to target. If it’s the main menu that’s within the header part of a page, it’s often the call from header.php template (or a referenced template part) if you use a classic theme.
Since you’ve not indicated which theme, I cannot even hazard a wild guess. And unless it’s a free and open source theme, I couldn’t say even if I knew your theme. I can say however, that if “theme_location” isn’t working, your theme is most likely passing a “menu” parameter in order to get the right menu. Either way, the solution is to determine how your theme is managing this.
I can confirm that Muhammad’s suggested code does work on a Twenty Twenty-one theme, so the only reason for failure is a conditional inappropriate for your theme.
But wait! One other possible reason: caching. The code could be working but you’re seeing stale, cached content. Always try clearing any caches, both client and server side before deciding certain code does not work.