
497 S.E.2d 412 (1998)
348 N.C. 39
Paul L. WHITFIELD, P.A., a North Carolina Professional Association
v.
Peter S. GILCHRIST, III, as District Attorney of the 26th Judicial District of the State of North Carolina; and the State of North Carolina, a sovereign governmental entity.
No. 287PA97.
Supreme Court of North Carolina.
April 3, 1998.
*413 Whitfield and Whitfield, P.A. by Paul L. Whitfield; and Odom & Groves, P.C. by T. LaFontine Odom, Charlotte, for plaintiff-appellee.
Michael F. Easley, Attorney General by Charles J. Murray, Special Deputy Attorney General, for defendant-appellant State of North Carolina.
MITCHELL, Chief Justice.
The question presented for review is whether the doctrine of sovereign immunity bars recovery in quantum meruit upon an action based on a contract implied in law against the State of North Carolina. We conclude that a contract implied in law is insufficient to constitute a waiver of sovereign immunity. We therefore reverse the decision of the Court of Appeals.
Plaintiff made the following allegations in the complaints filed for this action. Plaintiff is a professional association, and plaintiff's attorney, Paul F. Whitfield, is the principal attorney in the professional association. Defendant Peter S. Gilchrist is the District Attorney for the Twenty-Sixth Judicial District of North Carolina, which includes the City of Charlotte. Since 1967, Mr. Whitfield has brought various public nuisance actions within the City of Charlotte under chapter 19 of the General Statutes of North Carolina. Defendant Gilchrist engaged plaintiff Whitfield to file two public nuisance actions, one of *414 which was against the Downtown Motel Corporation, a North Carolina corporation, known as the Downtown Motor Inn and located on North Tryon Street in the City of Charlotte (Downtown Motel action). The second action was against Ashak Patel, Mani, Inc., a North Carolina corporation, doing business as Alamo Plaza Hotel Courts, Alamo Plaza Courts & Alamo Amusements, et al., in the City of Charlotte (Alamo action). In the investigation and preparation for both of these actions, plaintiff worked continuously with defendant Gilchrist as District Attorney and with members of the Charlotte Police Department. As a consequence of plaintiff's legal efforts, the public nuisances were abated. The Charlotte-Mecklenburg community, the public at large, and the State have benefitted, and plaintiff expected to be paid for its legal services.
On 28 July 1995, plaintiff filed a complaint alleging that it was entitled to recover from defendants, on the basis of quantum meruit, attorney's fees and costs for legal services it provided in the Downtown Motel public nuisance action. On 20 September 1995, defendants filed an answer and a motion to dismiss.
On 23 October 1995, plaintiff filed a second complaint with similar allegations seeking recovery in quantum meruit for its services in the Alamo action. Defendants filed a motion to consolidate the two cases on 26 October 1995. On 20 November 1995, defendants filed an answer and a motion to dismiss in the Alamo action.
The motions were heard at the 18 January 1996 Civil Session of Superior Court, Mecklenburg County. On 9 February 1996, the trial court entered an order allowing the consolidation of the two cases. In that same order, the trial court dismissed both actions, concluding that sovereign immunity is a complete defense to plaintiff's actions. Plaintiff then appealed to the Court of Appeals.
The Court of Appeals affirmed the trial court's dismissal of plaintiff's claims against defendant Gilchrist. Paul L. Whitfield, P.A. v. Gilchrist, 126 N.C.App. 241, 251, 485 S.E.2d 61, 67 (1997). The Court of Appeals reversed the trial court's dismissal of plaintiff's claims against defendant State of North Carolina and remanded the case for further proceedings with regard to those claims against the State. Id.
On 23 June 1997, defendant State petitioned this Court for discretionary review seeking to have this Court resolve a single issue: "Did the Court of Appeals err in holding that sovereign immunity is not available to the State as a defense to a pleading alleging a claim based on a quasi-contract implied in law which totally fails to comply with the applicable statutory requirements?" On 23 July 1997, this Court entered an order allowing discretionary review. Our appellate review here is limited solely to the single issue brought forward by defendant State in its petition for discretionary review.
Defendant State contends that the Court of Appeals erred in reversing the trial court's dismissal of plaintiff's claims against the State of North Carolina because sovereign immunity bars recovery on the basis of quantum meruit in an action against the State upon a quasi contract or contract implied in law. We agree.
It has long been the established law of North Carolina that the State cannot be sued except with its consent or upon its waiver of immunity. Guthrie v. N.C. State Ports Auth., 307 N.C. 522, 534, 299 S.E.2d 618, 625 (1983). This Court has held, however, that "whenever the State of North Carolina, through its authorized officers and agencies, enters into a valid contract, the State implicitly consents to be sued for damages on the contract in the event it breaches the contract." Smith v. State, 289 N.C. 303, 320, 222 S.E.2d 412, 423-24 (1976). In the decision below, the Court of Appeals improperly expanded Smith to hold that sovereign immunity does not bar an action seeking recovery in quantum meruit based on an implied-in-law contract theory. Whitfield, 126 N.C.App. at 248, 485 S.E.2d at 67.
Quantum meruit is a measure of recovery for the reasonable value of services rendered in order to prevent unjust enrichment. Potter v. Homestead Preservation Ass'n, 330 N.C. 569, 578, 412 S.E.2d 1, 7 (1992); see also Dan B. Dobbs, Dobbs Law of *415 Remedies § 4.2(3) (2d ed. 1993). It operates as an equitable remedy based upon a quasi contract or a contract implied in law. Potter, 330 N.C. at 578, 412 S.E.2d at 7. "A quasi contract or a contract implied in law is not a contract." Booe v. Shadrick, 322 N.C. 567, 570, 369 S.E.2d 554, 556 (1988). An implied contract is not based on an actual agreement, and quantum meruit is not an appropriate remedy when there is an actual agreement between the parties. Id. Only in the absence of an express agreement of the parties will courts impose a quasi contract or a contract implied in law in order to prevent an unjust enrichment. Id.
We will not imply a contract in law in derogation of sovereign immunity. In Smith, we held that when the State, acting through officers and agencies authorized by law, enters into a valid contract, it implicitly waives its sovereign immunity and consents to be sued for damages upon its breach of the contract. Smith, 289 N.C. at 320, 222 S.E.2d at 423-24. We emphasized, however, that "[t]he State is liable only upon contracts authorized by law. When it enters into a contract it does so voluntarily and authorizes its liability. Furthermore, the State may, with a fair degree of accuracy, estimate the extent of its liability for a breach of contract." Id. at 322, 222 S.E.2d at 425 (emphasis added). Consistent with the reasoning of Smith, we will not first imply a contract in law where none exists in fact, then use that implication to support the further implication that the State has intentionally waived its sovereign immunity and consented to be sued for damages for breach of the contract it never entered in fact. Only when the State has implicitly waived sovereign immunity by expressly entering into a valid contract through an agent of the State expressly authorized by law to enter into such contract may a plaintiff proceed with a claim against the State upon the State's breach. Id.
The State has not authorized its district attorneys to contract for payment of fees for attorneys' services of any type. To the contrary, as we explain hereinafter, the legislature has provided that such contracts may be entered only by, or with the approval of, other agents of the State. We certainly will not imply a contract in law where there is a statute to the contrary.
It is important to recognize that there are situations in which a district attorney may obtain the assistance of private counsel. For example, an elected district attorney has the discretion to permit a private attorney to appear with him to represent the State's interest in an action, subject to the court's approval. State v. Camacho, 329 N.C. 589, 593, 406 S.E.2d 868, 871 (1991). Historically, however, private counsel functioning in this prosecutorial capacity either have been paid by private parties or have appeared pro bono publico. See State v. Best, 280 N.C. 413, 186 S.E.2d 1 (1972). A district attorney's discretion to permit an attorney to act as a private prosecutor on behalf of the State in the prosecution of a particular case does not expressly or implicitly include the authority for the district attorney to bind the State to pay the attorney for performing the historic role of a private prosecutor.
More recently, the General Assembly has expressly provided authority for the State's district attorneys to employ private attorneys to exercise a more expansive prosecutorial power than that historically exercised under our common law by private prosecutors who were empowered to act only in individual cases. N.C.G.S. § 7A-64(2) sets out the mandatory procedure for a district attorney to follow to appoint private counsel to provide temporary assistance when criminal dockets are overcrowded. N.C.G.S. § 7A-64(2) (1995). Approval by the Administrative Officer of the Courts is required before a district attorney may make any such appointment. Significantly, N.C.G.S. § 7A-64 also mandates that "[t]he length of service and compensation of such temporary appointee shall be fixed by the Administrative Officer of the Courts in each case." Id., para. 2. The district attorney has no power to provide for compensation of an attorney appointed under this statute. The statute is public notice that compliance with its terms is required before such an attorney will be compensated by the State.
Another important statute, N.C.G.S. § 147-17 (1993), sets out the procedure required for the State to enter a valid contract *416 to employ outside counsel for purposes other than those contemplated by N.C.G.S. § 7A-64. Only after the provisions of N.C.G.S. § 147-17 have been followed will the State be deemed to have entered a valid contract for attorney's fees and thereby to have implicitly waived its sovereign immunity and consented to be sued in the event of its breach.
N.C.G.S. § 147-17 directs that no State official or agency may employ outside counsel without the Governor's approval. That statute also mandates that before such counsel may be employed, the Attorney General must provide the Governor with a determination that it is impractical for the Attorney General to render the necessary legal services for the State. Finally, the Governor must determine the amount of compensation that the attorney to be employed will receive and may determine the source of State funds for the compensation. All of these specific requirements must be satisfied in order for the State to have entered a valid contract with outside counsel to represent the State's interest. Otherwise, no valid contract exists. The State's sovereign immunity will be waived by implication only once all of the requirements of N.C.G.S. § 147-17 are met and a valid contract has been entered. This statute serves as public notice of its requirements.
Even though plaintiff could not expect to recover from the State on a theory based upon the State's implicit waiver of sovereign immunity, parties bringing such actions are not left without a means of compensation for maintaining civil nuisance actions. N.C.G.S. § 19-8 provides the procedure for the award of attorney's fees and costs in a public nuisance action. The enactment of N.C.G.S. § 19-8 indicates that the legislature contemplated only one noncontractual method of payment for attorneys who undertake to maintain, on behalf of anyone, a civil action to abate a nuisance as authorized by N.C.G.S. § 19-2.1. Under N.C.G.S. § 19-8, a prevailing party is awarded, in the trial court's discretion, attorney's fees as part of the costs of maintaining the action. N.C.G.S. § 19-8 gave plaintiff statutory notice of the sole method of compensation of private attorneys maintaining public nuisance actions for other persons. The fact that a district attorney may permit an attorney to bring a public nuisance action in his name does not mean that the district attorney may, acting alone, also enter into a valid contract binding the State to pay attorney's fees. In public nuisance actions, an attorney for the party maintaining the action receives compensation from the costs awarded that party should the party prevail. Surely, plaintiff knew this, as it alleges in its complaint that it has brought more than one hundred such actions in the past.
Neither of plaintiff's two complaints allege compliance with N.C.G.S. § 147-17, nor has the State in any other manner entered into a valid contract with plaintiff for legal services. A contract implied in lawas opposed to an express valid contractsimply will not form a sufficient basis for a court to make a reasonable inference that the State has intended to waive its sovereign immunity. N.C.G.S. § 19-8 is the proper source of compensation for an attorney representing a prevailing party in a public nuisance action, at least when the State has not expressly entered into a valid contract for such legal services.
For the foregoing reasons, the trial court correctly dismissed plaintiff's claims against defendant State of North Carolina, and the decision of the Court of Appeals to the contrary was in error. The decision of the Court of Appeals on this issue is reversed, and this case is remanded to that court for its further remand to the Superior Court, Mecklenburg County, for reinstatement of the order dismissing all claims against the State.
REVERSED AND REMANDED.
