An act or a transfer of property to or by a cooperative is not invalid because it is in excess of the cooperative's power to do the act or make or receive the transfer, except that the lack of power may be asserted in a proceeding by
(1) a member, shareholder or director against the cooperative to enjoin an act or transfer of property to or by the cooperative; if the unauthorized act or transfer sought to be enjoined is being, or is to be, performed or made under a contract to which the cooperative is a party, the court may, if all of the parties to the contract are parties to the proceeding and if it considers it equitable, set aside and enjoin the performance of the contract, and in so doing may allow to the cooperative or to the other parties to the contract compensation for the loss or damage sustained by either of them resulting from the action of the court in setting aside and enjoining the performance of the contract; but the court may not award anticipated profits to be derived from the performance of the contract as a loss or damage sustained;
(2) a cooperative, its legal representative, or through its members or shareholders in a representative suit, against the officers or directors or former officers and directors of the cooperative;
(3) the attorney general against the cooperative in an action to dissolve the cooperative or to enjoin it from the transaction of unauthorized business.