Heat 4 tbsp butter in a large skillet over medium-high heat. Add the onions and cook while stirring occasionally until caramelized, about 7 minutes.
Add the mushrooms and cook for 4 minutes, then add the minced garlic and cook for 1 minute. Transfer to a bowl.
Add 4 tbsp butter to the same skillet and once melted add the flour and whisk together. Cook for about 2 minutes.
Add the half n half, salt, and pepper, and cook for 5 minutes while stirring, until thick.
Preheat the oven to 350ºF. Bring a large pot of water to a boil and add the green beans. Cook for 7 minutes, then drain.
Add the onion mixture to the sauce and stir well.
Add the green beans and Parmesan cheese and toss to combine.
Transfer everything to a 9x9-inch baking dish and bake in the oven for 25 minutes, then top with the fried onions and continue baking for an additional 5 minutes.