Don't feel too bad, it's a relatively new car. Unfortunately your car is on its periodic replacement parts cycle. What is costing so much to pass emissions? Catalytic converter? O2 sensors are cheap, as well exhausts.
I brought my 1987 BMW 325e to my mechanic last week for emissions inspection, rear trunk seal replacement, tie-rod replacement and rear window replacement. Still waiting for the rear window from the dealer. Before that, just regular maintenance for last 4 years. The tranny and engine are still strong at 195,000 miles. Before that, I had a 1990 BMW 325is with 220,000 miles and ran like a top for 3 years. Only had to do routine maintenance on it. Still sorry I sold that car and kept my 1969 BMW 1600/2002. Now that's a money pit every time I drive it, so I only drive it every other year.