*138Ramin Ahmed was convicted of possession of marijuana for sale, transportation of marijuana, and money laundering. He contends the trial court erred when it prohibited him from asserting a medical marijuana defense, that it gave a number of erroneous jury instructions, and that his attorney provided constitutionally inadequate representation. The court's ruling barring Ahmed's medical marijuana defense violated his constitutional right to present a defense, so we reverse.
BACKGROUND
Ahmed operated a business in Livermore selling medical marijuana products. Livermore, however, has a municipal ordinance that prohibits marijuana dispensaries. In February 2014 the city issued an administrative citation for violating the ordinance and ordered him to cease operations.
In January 2015 undercover officers purchased a small quantity of marijuana from Ahmed after being required to sign a membership agreement and produce identification, state medical marijuana cards and physicians' recommendations. In February police searched Ahmed's business and seized financial records, approximately $26,000 in cash, 18 pounds of marijuana, and 37 ounces of marijuana oils, wax and edibles. They also obtained and executed search warrants for Ahmed's bank records, which reflected a number of cash *139deposits of between $1,000 and $11,000 and several purchases for personal rather than business purposes.
Ahmed was arrested and charged with two counts of possession of marijuana for sale, four counts of money laundering, and two counts of transportation of marijuana.
The Court Disallows a Medical Marijuana Defense
The prosecution moved before trial to preclude Ahmed from raising a medical marijuana defense. They asserted, inter alia, the defense was inapplicable "because Livermore Municipal Code 05.80.20 completely prohibits dispensaries within it's [sic ] jurisdiction. ... [¶] Based on the City of Livermore's restriction on the establishment of dispensaries the defendant was *474not operating a lawful collective and therefore should not be allowed to rely on" a medical marijuana defense under the Compassionate Use Act or the Medical Marijuana Program Act.
The court relied primarily on City of Riverside v. Inland Empire Patients Health and Wellness Center, Inc. (2013) 56 Cal.4th 729, 156 Cal.Rptr.3d 409, 300 P.3d 494 ( Riverside ) in its tentative ruling granting the motion. It explained: "[W]hen they considered what are we going to do with the cooperatives, the collectives, the dispensaries operators establishments, or providers, under [ Health and Safety Code section] 11362.7681 the Legislature said, okay, we're going to let the cities decide as to whether or not they are going to let any of those collectives or cooperatives into their city and set up business, set up shop. They can decide whether to allow them to set up shop. They can decide if they let them set up shop, where, and under-you know, they can set it by zoning laws, say where and what hours you can operate, and that kind of stuff. That-[section] 11362.768 says, in paragraph (f), nothing in this section shall prohibit a city, county, or city and county from adopting ordinances or policies that further restrict the location of establishment of a medical marijuana cooperative, collective, dispensary, operator, establishment or provider. So, cities, or counties, or city and county, which applies only to San Francisco, can restrict those things. They can keep them out entirely. They can let them be there under certain conditions. That's the power of the City.
"So then you have this-so I think the State, when the Legislature made this law, said two things. One is the individual person who needs the medical marijuana, they're protected from law. But the person who's running the *140business, the cooperative, or the collective, they have to follow the rules that the City sets up. If the City says we don't want you here, then you can't set up in that city. Then those laws will apply to you.
...
"And if that city has an ordinance that says you can't do it, then you can't do it in that city. If you do do it in that city, there is no defense to the charge." The court adopted its tentative ruling after ascertaining that Riverside remained good law.
Jury Instructions
The jury was instructed consistently with the ruling on the prosecution's motion in limine. Quoting from and paraphrasing Riverside, the court instructed the jury: "The California Constitution recognizes the broad authority of cities to make, enforce, and determine the appropriate use of land within their borders.
"While some counties and cities might consider themselves well suited to accommodating medical marijuana dispensaries, conditions in other communities might lead to the reasonable decision that such facilities within their borders, even if carefully sited, well managed, and closely monitored, would present unacceptable local risks and burdens.
"A city ordinance can regulate the use of its land, including the authority to restrict the establishment of facilities that furnish, distribute, or make available medical marijuana within the city's borders. In the exercised [sic] of its land use power, the City of Livermore has declared, by Livermore Municipal Code § 5.80, that:
" 'A medical marijuana dispensary shall not be established; operated, or maintained at any location within the city of Livermore.' "
*475On the first day of deliberations the jury asked the court several questions about medical marijuana, including whether "if it's illegal to have a dispensary in Livermore, does it make it illegal to sell marijuana on the state level." In response, the court repeated its instruction that "[t]he law allows local jurisdictions to enact ordinances to regulate use of its land, including the authority to provide that facilities for distribution of medical marijuana will not be permitted to operate within its borders. [¶] Some counties and cities might consider themselves well suited to accommodating medical marijuana dispensaries, but conditions in other communities might lead to the reasonable decision that such facilities within their borders, even if carefully sited, well managed, and closely, would present unacceptable local risks and burdens."
*141The next day the jury asked the court for "the criteria, guidelines, requirements considered by the state of CA in order to sell and/or distribute medical marijuana by collectives, dispensaries, operator, or other products?" and "the criteria, guidelines, requirements considered by the State of CA in order to open a collective/dispensary?" The court instructed the jury that "Collectives and dispensaries must follow local laws, codes, and city ordinances under the laws of the State of California."
The jury continued to wrestle with questions about medical marijuana. The following day the jury requested the text of the code section "pertaining to medical marijuana and collectives" and asked: "Is it illegal, specifically under California state law, to do any of the following? [¶] ... For a collective/dispensary of medical marijuana to operate while knowingly being not in compliance with a local law or ordinance?" The court responded by providing the jury with the text of sections 11359 (possession for sale), 11360, subdivision (a) (sale) and Penal Code section 186.10 (money laundering). It did not give the jury the text of the Compassionate Use Act of 1996 (CUA; § 11362.5) or Medical Marijuana Program (MMP; § 11362.7 et seq.), but referred the jury to "the instructions already given concerning medical marijuana collectives or dispensaries."
Verdict and New Trial Motion
Ahmed was convicted of distributing marijuana and possessing marijuana for sale and four counts of money laundering, the latter of which were premised on the marijuana charges. The court declared a mistrial on the transportation counts after the jury was unable to reach a verdict on them.
Ahmed requested leave to move for a new trial on the grounds that the court erroneously (1) precluded him from raising the state medical marijuana defense on the basis that Livermore's local ban against dispensaries preempted the state law defense to a criminal prosecution; and (2) instructed the jury that it is illegal under California law for a legal medical marijuana dispensary to deposit money into a federal bank. The court denied the request. Ahmed was sentenced to five years' felony probation with conditions including one year in county jail, a $5,000 restitution fund fine, and approximately $82,000 in other fines and fees. This appeal was timely filed.
DISCUSSION
Did the trial court err in barring Ahmed from asserting a medical marijuana defense? Yes, and the error requires reversal.
*142I. Riverside Does Not Authorize Local Governments to Abrogate the State Law Medical Marijuana Defense
As explained in *476Riverside, supra, 56 Cal.4th at p. 737, 156 Cal.Rptr.3d 409, 300 P.3d 494, "[b]oth federal and California laws generally prohibit the use, possession, cultivation, transportation, and furnishing of marijuana. However, California statutes, the Compassionate Use Act of 1996 [citation] and the more recent Medical Marijuana Program [citation] have removed certain state law obstacles from the ability of qualified patients to obtain and use marijuana for legitimate medical purposes." To that end, the MMP provides that "qualified patients, persons with valid identification cards, and the designated primary caregivers of qualified patients and persons with identification cards, who associate within the State of California in order collectively or cooperatively to cultivate cannabis for medicinal purposes, shall not solely on the basis of that fact be subject to state criminal sanctions under [s]ection 11357 [possession], 11358 [cultivation, harvesting and processing], 11359 [possession for sale], 11360 [transportation, sale, furnishing or administration], 11366 [maintenance of place for purpose of unlawful sale, use or furnishing], 1136.5 [making place available for purpose of unlawful manufacture, storage, or distribution], or 11570 [place used for unlawful sale, serving, storage, manufacture or furnishing as statutory nuisance]." (§ 11362.775, subd. (a); Riverside, supra, 56 Cal.4th at p. 739, 156 Cal.Rptr.3d 409, 300 P.3d 494.)
Relying on Riverside, the trial court here ruled prior to trial that the medical marijuana defense was unavailable to Ahmed as a matter of law because Livermore Municipal Code section 5.80.020 prohibits commercial cannabis activity within city limits. In doing so, the court misinterpreted Riverside . The issue in Riverside was whether the CUA and MMP preempt the ability of local governments to ban medical marijuana dispensaries within their boundaries. ( 56 Cal.4th at p. 737-739, 156 Cal.Rptr.3d 409, 300 P.3d 494.) The Court held they do not. It explained: "the MMP merely removes state law criminal and nuisance sanctions from the conduct described therein. By this means, the MMP has signaled that the state declines to regard the described acts as nuisances or criminal violations, and that the state's enforcement mechanisms will thus not be available against these acts. Accordingly, localities in California are left free to accommodate such conduct, if they choose, free of state interference. As we have explained, however, the MMP's limited provisions neither expressly nor impliedly restrict or preempt the authority of individual local jurisdictions to choose otherwise for local reasons, and to prohibit collective or cooperative medical marijuana activities within their own borders. A local jurisdiction may do so by declaring such conduct on local land to be a nuisance, and by providing a means for its abatement." ( Id . at p. 762, 156 Cal.Rptr.3d 409, 300 P.3d 494.)
*143Nothing in Riverside 's application of preemption principles supports the trial court's conclusion that a local ban on dispensaries abrogates the medical marijuana defense in a prosecution under state criminal law. While a local government remains free to enact local ordinances to regulate (or prohibit) medical marijuana operations within its jurisdiction ( Riverside, supra , 56 Cal.4th at p. 762, 156 Cal.Rptr.3d 409, 300 P.3d 494 ; see also § 11362.83; Kirby v. County of Fresno (2015) 242 Cal.App.4th 940, 961, 195 Cal.Rptr.3d 815 ), nothing in law or logic supports an extension of local government power over land use within its borders to, in effect, nullify a statutory defense to violations of state law. How could it? A city or county has no power to preempt state law. Nor does any language in the MMP or CUA even arguably suggest the defense provided by section 11362.775, subdivision (a) is available only to medical marijuana providers who are *477compliant with local ordinances. The court's ruling that Ahmed's violation of the Livermore ordinance barred him raising a medical marijuana defense under the MMP was thus erroneous as a matter of law.
The People, to their credit, do not appear to contend otherwise. Rather, they argue Ahmed failed to show he could establish a medical marijuana defense through evidence that he was a qualified patient, a person with a valid identification card or a designated primary caregiver who associated with others to collectively or cooperatively cultivate marijuana. (See § 11362.775, subd. (a).) The argument is at best unpersuasive. The trial court barred Ahmed from asserting a medical marijuana defense as a matter of law , without regard to Ahmed's evidentiary support for such a defense, before he had any reason or occasion to make a proffer. It is particularly unpersuasive, then, for the People to implicitly concede this legal error on appeal but defend the conviction by arguing Ahmed failed to proffer evidence that the error rendered irrelevant.
In any event, the record does not bear out the People's claim that Ahmed could not substantiate an MMP defense. At the outset of trial defense counsel advised the court, "this is a medical marijuana collective slash dispensary case. ... [¶] You had to have [a] medical marijuana card. You had to have a prescription from our doctor. You had to have a driver's license to go into his open store to purchase." When the court asked defense counsel whether he had evidence supporting a medical marijuana defense, counsel responded, "I have testimony, I have documents. You want me to show you some of the documents? ... [¶] I have no problem with doing that in this case. I am absolutely open." Ahmed testified at trial that the collective was being run properly and without criminal activity; that he did nothing illegal; that only patients with medical cards were permitted in the sales room; that he paid sales and employee payroll taxes; and that the collective was a non-profit, with any profits received put back into the business "for the patients." One of the investigating officers testified that out of 1,400 or 1,500 collective members *144whose records were seized only 5 or 6 had not provided California I.D.'s, and the officer was unable to identify any individuals who had not provided a physician's recommendation for marijuana. The People's current position that Ahmed failed to show he could assert a medical marijuana defense simply ignores all of this.
"Whether rooted directly in the Due Process Clause of the Fourteenth Amendment, Chambers v. Mississippi2 ... or in the Compulsory Process or Confrontation clauses of the Sixth Amendment, [citations], the Constitution guarantees criminal defendants 'a meaningful opportunity to present a complete defense. [Citations.] We break no new ground in observing that an essential component of procedural fairness is an opportunity to be heard.' " ( Crane v. Kentucky (1986) 476 U.S. 683, 690, 106 S.Ct. 2142, 90 L.Ed.2d 636 ; California v. Trombetta (1984) 467 U.S. 479, 485, 104 S.Ct. 2528, 81 L.Ed.2d 413 ; see also People v.Stewart (1976) 16 Cal.3d 133, 141, 127 Cal.Rptr. 117, 544 P.2d 1317 [erroneous failure to instruct on affirmative defense "constitutes a denial of this right which 'is in itself a miscarriage of justice' "].) This case exemplifies a deprivation of the right to assert a defense. It cannot be said on this record that the refusal to permit Ahmed's possible medical marijuana defense was harmless beyond a reasonable *478doubt. ( Chapman v. California (1967) 386 U.S. 18, 24, 87 S.Ct. 824, 17 L.Ed.2d 705.) We must reverse.3
DISPOSITION
The judgment is reversed.
We concur:
McGuiness, Acting P.J.*
Jenkins, J.
Unless otherwise noted, further statutory citations are to the Health and Safety Code.
Chambers v. Mississippi (1973) 410 U.S. 284, 93 S.Ct. 1038, 35 L.Ed.2d 297.
We therefore will not address Ahmed's additional challenges to a number of jury instructions or his assertion of ineffective assistance of defense counsel.
Retired Presiding Justice of the Court of Appeal, First Appellate District, Division Three, assigned by the Chief Justice pursuant to article VI, section 6 of the California Constitution.