In most of the cases, our X++ classes have to be executing within the server (AOS). In a default deployment we're not able to debug server code.
To have this Dynamics AX feature, we must enable it in ‘Microsoft Dynamics AX Server Configuration Utility’ tool (within 'Administrative Tools' menu).
You may need to use the Manage button to Create a new Configuration. Then, on the first tab, Application Object Server, make sure that the check box option "Enable breakpoints to debug X++ code running on this server" is checked.
There is a direct registry key to do it, too. (but this way may be not supported):