question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GenerateSetupCode starts throwing GDI+ errors after a random period

See original GitHub issue

Hi, Thanks for writing an maintaining this! It does exactly what we need, except when it doesn’t.

We’re using this in a web app for 2FA. It runs fine for a random time period, but then starts throwing GDI+ errors for all calls to GenerateSetupCode. The first time, it only ran for about an hour with low volume. The second time it ran for 3 days with periods of high volume (5000 calls in a minute). The only thing that solves the problem is to reset the site in IIS.

I’ve watched TaskManager when generating the codes. The memory usage jumps while it’s processing, but then drops back down, so doesn’t seem like a memory leak.

Here’s the code we’re using (the real code only makes one call, of course, but this is what I’ve been testing with):

int qrCodeCount = 100;

for (int i = 0; i < qrCodeCount; i++)
{
	string key = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);

	TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
	SetupCode setupInfo = tfa.GenerateSetupCode("Test Portal", "SAMPLE" + key, key, false, 3);
	if (setupInfo != null)
	{
		System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
		img.ImageUrl = setupInfo.QrCodeSetupImageUrl;
		//lblManualSetupCode.Text = setupInfo.ManualEntryKey;
		phQRCodes.Controls.Add(img);
	}
}

And the exception:

System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.    
 at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)    
 at Google.Authenticator.TwoFactorAuthenticator.GenerateQrCodeUrl(Int32 qrPixelsPerModule, String provisionUrl)    
 at Google.Authenticator.TwoFactorAuthenticator.GenerateSetupCode(String issuer, String accountTitleNoSpaces, Byte[] accountSecretKey, Int32 qrPixelsPerModule, Boolean generateQrCode)    
 at TopLineGroup.Web.Admin_OtherSiteMaintenance.lbTestMFAQRCodes_Click(Object sender, EventArgs e) in E:\...\OtherSiteMaintenance.aspx.cs:line 207

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
MarkHeddaeuscommented, May 25, 2022

So far so good with the beta.

I ran it manually on Friday and this morning with 100 codes every hour or so. And today I set it up to automatically refresh every 10 seconds, and I’m running it simultaneously in 15 tabs over 3 browsers with no problems.

How close it the beta to release? I’d like to try it in our live site, but if there are other known issues…

1reaction
MarkHeddaeuscommented, May 23, 2022

I get pretty much the same thing. Generating blocks of 100 at a time have no problem. It just randomly stops working at some point.

I have it running with the beta in a test environment now. I’ll periodically generate 100 or so and see if it breaks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A generic error occurred in GDI+, for random images
Often gdi errors are caused by you trying to change something that you think you "own" when the loader thinks it owns it....
Read more >
The dreaded “A generic error occurred in GDI+.” Exception
This works most of the time (1000s) but sometimes I get this GDI exception. This uses .net 4.8, Asp.Net, and fails on both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found