Sign in to follow this  
DrawMusic

[.net] Font ctor throws exception, how?

Recommended Posts

DrawMusic    122
I had a customer report an exception which seemed to be thrown by the Font ctor when the font was missing (my code tried to create a "Verdana" Font object and he had deleted his Verdana font). However, I can't repro the exception on my PC. When I try to create a Font with a nonexistent facename (I tried "notVerdana"), I get no exception, just a working default font. Does anyone know a test configuration (Windows version, .NET version, bad font installation?) which will make the Font ctor throw an exception?

Share this post


Link to post
Share on other sites
mutex    1111
What's the exception, including callstack? You can dig through System.Drawing.Font's implementation using .NET Reflector and see how the exception is getting thrown.

Another thing you can try is actually installing a new font, then deleting it the same way the customer deleted it (i.e. either deleting the .ttf file or using Explorer and deleting it from the Fonts folder). Some font information exists in the registry, and deleting only the .ttf file won't update it. This might be the exception cause.

Share this post


Link to post
Share on other sites
DrawMusic    122
Unfortunately, since this is just a customer report, I can't get the exact exception or call stack, which is why I went fishing here. I think his .NET error message just said he had an "unhandled exception" without saying what it was.

mutex, good point on the Registry. My repro attempt didn't really match the user's case very closely.

My code which threw isn't very interesting:

c_fontPrompt = new Font( "Verdana", 12, ChordsLineUtils.c_eFontGraphicsUnit );

Anyway, the good news is this customer reinstalled Verdana and fixed his problem.

I also got a tip on another forum that this might happen if the user also deleted the backstop font, MS Sans Serif.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this