Preheat the oven to 350°F (175°C).
In a skillet, melt the butter over medium heat. Add the chopped onion and cook until soft, about 5 minutes.
Stir in the flour and cook for an additional 1-2 minutes, stirring constantly until the mixture is golden.
Gradually whisk in the heavy cream and milk, stirring constantly until the sauce thickens, about 3-5 minutes.
Add salt, pepper, and half of the grated cheese to the sauce, stirring until melted and combined.
In a baking dish, combine corn kernels and the cheese sauce, mixing well to coat.
Sprinkle the remaining cheese over the top of the corn mixture, and optionally, some breadcrumbs for added crunch.
Bake in the preheated oven for 30–35 minutes, or until golden and bubbly.