Current code badly broken - circular logic trying to get settings path

Topics: Business Logic Layer
Aug 31, 2007 at 10:14 PM
I've just downloaded the latest code, and it fails to load in IE with an exception. It seems to be because in XmlBlogProvider, we have this:

private static string _Folder = System.Web.HttpContext.Current.Server.MapPath(BlogSettings.Instance.StorageLocation);

But the Instance property of BlogSettings contains this:

string filename = _Folder + "settings.xml";

So it seems we're trying to find the folder by loading the settings out of a file inside the unknown folder. So while trying to set the static string _Folder, we actually run code that uses Folder to find the settings. There's no way this can ever work (Folder will be null when trying to load the settings, to settings.xml will be looked for in the "current" folder - which for me was Program Files\Visual Studio!

For now I'm just going to hard-code it locally (I'm just checking how far it's come - I want to start implementing it soon though), but if you can't reproduce it or need any more info, reply to this post - I've got email notifications on :-)
Aug 31, 2007 at 10:26 PM
This should be changed to use a property from web.config for the folder to run MapPath on, like:

private static string _Folder = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings"dataFolder".ToString());

Or you could hard code it to use "~/App_Data/" but I don't know if you want to do that or not design-wise.

Also, instances of file paths should use the Path type instead of just strings if possible.
Sep 1, 2007 at 8:17 AM
Yeah, I'd agree with the web.config option.

There's also a Path.Combine rather than just doing _Folder + "settings.xml" which will make sure you get a "\" between if needed :D
Sep 1, 2007 at 6:59 PM
the static initialized _Folder resolves to %SYSTEMROOT%\system32\inetroot" on my devbox. it's called prior to LoadSettings() by the CLR. static initializers are just weird things that may or may not run prior to first usage.