WordPress.com had a nice end-of-year present too: inserting a backslash (\) before every single (‘) or double (“) quote on various sites:
It\’s not your fault. Code rots. We don\’t hold entropy against you, but we expect you to give a damn. This story is about code that brings new meaning to the word \’legacy\’. The accidental discovery of this body of code provoked a moral crisis. I wanted to pretend I hadn\’t seen it, yet I couldn\’t justify tiptoeing quietly away. This talk examines the dilemmas we face when balancing our choices today with their cost tomorrow. It\’s not your fault. Even so, it is your responsibility.
Before showing the code at the bottom of this blog post, let me explain the question in more detail:
Basically I was in the midst of refactoring some ‘inherited’ business logic code that – before refactoring – for the ASP.NET side needs to be initialized with an absolute path, but on the WinForms / WPF side only with a relative path to a GetExecutingAssembly directory.
To ease xcopy deployment, I wanted all configuration settings to be relative. But I hadn’t found a common means for these platforms to obtain a directory usable as a root for accessing relative files.
That way I could put identical settings in both the Web.config and App.config, heck even generate them based on a common fragment, whithout having to hard-code absolute path names.
I knew about Assembly.GetExecutingAssembly, but in ASP.NET that location is not where the web site is (both IIS and the WebDevelopment server make use of temporary locations to store the assemblies).
ASP.NET does have Server.MapPath and HostingEnvironment.MapPath, but I didn’t want to make the business logic depend on ASP.NET.