开发者

Out of Memory error in Visual Studio 2008, opening WinForms designer. How to solve?

I'm using Visual Studio and while fiddling around with a custom control, I started to get an out of memory error.

Out of Memory error in Visual Studio 2008, opening WinForms designer. How to solve?

The stack tr开发者_如何学Pythonace is not helpful - it's just a bunch of frames doing Reflection and so on.

Out of Memory error in Visual Studio 2008, opening WinForms designer. How to solve?

How can I fix this?


There was a problem in the constructor of the custom control.

For some reason, calling Bitmap.MakeTransparent() on a bitmap that doesn't have a transparent bit set, causes an out of memory error.

This was being reported in the designer, but without any of the actually relevant stack trace.

The solution was to comb through the custom control and make sure the constructor could never through an exception. One approach is to surround the constructor logic in the control with a try...catch, and report the error with Console.WriteLine. You'll see it at runtime, with full stack trace.


Note: I searched the intertubes and saw a number of questions asking about similar problems, but nothing definitive for an answer. So I put this question + answer here hoping it might help someone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜