In a large skillet, heat 4 Tablespoons of butter over medium-high heat. Add onions and cook until tender and caramelized, about 7-8 minutes, stirring often. Add mushrooms and cook for 4 minutes longer. Stir in garlic and cook for 1 minute. Transfer the mixture to a bowl.
After the onion-mushroom mixture has been removed, use the same skillet. Heat skillet to a medium heat and add remaining 4 Tablespoons of butter. Add flour or cornstarch and begin to quickly whisk the mixture. Let cook, whisking often, for about 2 minutes. Stir in half-n-half, salt, and pepper. Cook for 4-5 minutes until mixture thickens. Taste and check for seasonings.
Preheat oven to 350 degrees. Bring a large pot of water to a boil. Add green beans and cook for 6-7 minutes. Drain and transfer to ice bath to cool (optional).
Add onion-mushroom mixture to cream sauce and stir. Add green beans and stir to coat. Sprinkle with parmesan cheese, if using. Pour into a 9 x 9 baking dish. Bake for 25 minutes or until bubbly. Remove from the oven and cover with fried onions. Bake for 5 minutes longer. Serve immediately, if possible.
Notes
May use fresh, frozen or canned green beans. If using canned green beans, they don't need to be cooked ahead of time.
Don't use anything less than half-n-half in these green beans as it creates a thick sauce.
If you want bite-size green beans, cut the fresh green beans in half.