{"id":5357,"date":"2014-03-30T21:02:56","date_gmt":"2014-03-30T21:02:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/fatalexecutionengineerror-was-detected-when-using-console-writeline-after-redefining-string-empty-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:02:56","modified_gmt":"2014-03-30T21:02:56","slug":"fatalexecutionengineerror-was-detected-when-using-console-writeline-after-redefining-string-empty-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/fatalexecutionengineerror-was-detected-when-using-console-writeline-after-redefining-string-empty-collection-of-common-programming-errors\/","title":{"rendered":"&ldquo;FatalExecutionEngineError was detected&rdquo; when using Console.Writeline after redefining String.Empty-Collection of common programming errors"},"content":{"rendered":"<p>If we look at the program<\/p>\n<pre><code>class Program\n{\n    static void Main()\n    {\n        Console.WriteLine(\"{}\", \"\");\n    }\n}\n<\/code><\/pre>\n<p>then it will fail with an <code>FormatException<\/code> with the error message <code>Input string was not in a correct format<\/code>.<\/p>\n<p>However when we insert <code>typeof(string).GetField(\"Empty\").SetValue(null, \" \");<\/code> before the line with <code>Console.WriteLine<\/code> then the code fails when it tries to look up that error message. If we look at the full stacktrace (including &#8220;Show external code&#8221;) then we see that the code fails at <code>System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(string fileName = \" mscorlib.resources\")<\/code> (notice the space in front of mscorlib.resources).<\/p>\n<p>The reason for this is that <code>ManifestBasedResourceGroveler<\/code> uses the metode <code>GetResourceFileName<\/code> of <code>ResourceManager<\/code> to find the resource file. And in <code>GetResourceFileName<\/code> we use a <code>StringBuilder<\/code> to construct the filename and the constructor of <code>StringBuilder<\/code> starts with <code>String.Empty<\/code>.<\/p>\n<pre><code>public StringBuilder(int capacity)\n    : this(String.Empty,capacity){\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If we look at the program class Program { static void Main() { Console.WriteLine(&#8220;{}&#8221;, &#8220;&#8221;); } } then it will fail with an FormatException with the error message Input string was not in a correct format. However when we insert typeof(string).GetField(&#8220;Empty&#8221;).SetValue(null, &#8221; &#8220;); before the line with Console.WriteLine then the code fails when it tries [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5357","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5357"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5357\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}