A contractor may not bring or maintain a court action to collect compensation for work requiring a license under this chapter unless the contractor alleges and proves that the contractor held the required license:
(1) when entering into the contract; and
(2) when the cause of action arose.