Bug 27515 - Enum.ToString() fails randomly in fastcgi-mono-server4 with FormatException
Summary: Enum.ToString() fails randomly in fastcgi-mono-server4 with FormatException
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-02-27 14:00 UTC by Steve Dennis
Modified: 2015-03-06 09:42 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Steve Dennis 2015-02-27 14:00:42 UTC
Sometimes calling .ToString() on any System.Enum value will throw either a FormatException or a NullReferenceException. If it happens once with a specific Enum type, then it continues to happen every time for that type until the hosting environment is restarted. Here's a stack trace:

ERROR building certificate chain: System.FormatException: Format String can be only "G","g","X","x","F","f","D" or "d".
  at System.Enum.Format (System.Type enumType, System.Object value, System.String format) [0x00000] in <filename unknown>:0
  at System.Enum.ToString () [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Store..ctor (StoreName storeName, StoreLocation storeLocation) [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Chain.get_UserRootStore () [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Chain.get_Roots () [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Chain.get_CertificateCollection () [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Chain.FindParent (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Chain.BuildChainFrom (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) [0x00000] in <filename unknown>:0
  at System.Security.Cryptography.X509Certificates.X509Chain.Build (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) [0x00000] in <filename unknown>:0
  at System.Net.ServicePointManager+ChainValidationHelper.ValidateChain (Mono.Security.X509.X509CertificateCollection certs) [0x00000] in <filename unknown>:0
Please, report this problem to the Mono team


Note that this seemed to happen somewhere within the BCL, as we are not using X509Certs directly anywhere. I've also seen it happen with enums that are defined within our code, but I can't consistently reproduce. Looking through the mono source on GitHub, I can only guess that somehow one of the dictionaries it uses internally to cache enum names is getting corrupted. Maybe a ThreadAbort from the ASP.NET hosting environment?
Comment 1 Marek Safar 2015-03-05 08:58:25 UTC
This should be fixed in mono master. Please re-test it if possible
Comment 2 Steve Dennis 2015-03-06 09:42:33 UTC
Great, thanks! Unfortunately I haven't gotten this to happen again using even the 3.12.0 version for several days, so I can't be of much help re-testing at the moment. If there was some way of triggering this behavior, I haven't discovered it yet.