While looking at source of Ayende's Racoon Blog, I saw this in global.asax.cs
:
// Work around nasty .NET framework bug
try
{
new Uri("http://fail/first/time?only=%2bplus");
}
catch (Exception)
{
}
This appears to be a workaround for a bug that happens on the first request. Does anyone know what the bug is or how to reproduce it?
A bit of googling gets to this Ayende blog post from March 2010 from which I quote an excerpt:
I can reproduce this now, here it how it got there:
public class Strange : MarshalByRefObject { public void WTF() { Console.WriteLine(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); new Uri("http://localhost:58080/indexes/categoriesByName?query=CategoryName%3ABeverages&start=0&pageSize=25"); } } public class Program { private static void Main() { var instanceAndUnwrap = (Strange) AppDomain.CreateDomain("test", null, new AppDomainSetup { ConfigurationFile = "" }).CreateInstanceAndUnwrap("ConsoleApplication5", "ConsoleApplication5.Strange"); instanceAndUnwrap.WTF(); } }
That took some time to figure out.
From the comment thread below, which I have skimmed but not read in detail, the root cause appears to be an error in the machine root config file, which is only parsed once per ?AppDomain
, hence the lack of an error the second and subsequent times.
Habitually using this construct having been burned by it once is the kind of habit that programmers accumulate through hard experience. The less experienced may snigger "cargo cult" or "programming by coincidence", to which the more experienced will just smile and nod.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With