Not your Grandmother's Green Bean Casserole!
Preheat oven to 375°F. Melt 2 tablespoons butter in a medium saucepan over medium-high heat. Add mushrooms, salt and pepper and cook, stirring occasionally, until liquid is absorbed and mushrooms are golden brown, 8 to 10 minutes; transfer to a small bowl and return saucepan to heat.
Melt remaining 3 tablespoons butter in pot over medium heat. Whisk in 1/4 cup flour and cook, whisking constantly, for 1 minute. Whisk in 2 cups milk until smooth then cook, stirring often, until silky and thickened, about 5 minutes. Remove from heat and add 1 1/2 cups Gruyère a handful at a time, gently stirring until melted; season generously with salt and pepper and set aside.
In large bowl, toss together green beans, mushrooms and Gruyère sauce then transfer to a 9x13-inch casserole dish and sprinkle remaining 1/2 cup Gruyère Cheese over the top; set aside.
Mix 1/4 cup flour, bread crumbs, cayenne and salt to taste in small bowl. In large bowl, toss onions with remaining 1/4 cup milk then add bread crumb mixture. Toss gently to coat. Scatter onions over green beans (along with any bread crumbs that didnt stick) and bake until golden brown and casserole is bubbly, about 40 minutes.
Let casserole stand 10 minutes before serving.