Legal Adviser: When a Permit Goes Bad

Imagine this scenario: A homeowner
hires you to build an addition, and
with permit in hand, you order the
materials, hire subs, and start work. At
the first inspection, with the foundation
poured and the framing up, the
code inspector says: "Nice foundation.
Nice framing. But you're too close to
the rear lot line. Our code requires
that residences be no less than 20 feet
away from the rear property line and
you're within 15 feet. You've got to
lose 5 feet of building there." And
then he shuts you down.
Along with creating a very bad day,
this situation raises several legal questions:
Does the building permit offer
you any protection, and if not, why
weren't you