public static class ConfigurationManager
{
+ static bool systemWebInUse;
static InternalConfigurationFactory configFactory = new InternalConfigurationFactory ();
static IInternalConfigSystem configSystem = new ClientConfigurationSystem ();
static object lockobj = new object ();
-
+
[MonoTODO ("Evidence and version still needs work")]
static string GetAssemblyInfo (Assembly a)
{
internal static Configuration OpenExeConfigurationInternal (ConfigurationUserLevel userLevel, Assembly calling_assembly, string exePath)
{
- if (calling_assembly == null && exePath == null)
- throw new ArgumentException ("exePath must be specified when not running inside a stand alone exe.");
-
ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
/* Roaming and RoamingAndLocal should be different
switch (userLevel) {
case ConfigurationUserLevel.None:
- if (exePath == null)
- exePath = calling_assembly.Location;
- else if (!File.Exists (exePath))
- exePath = "";
-
- if (exePath != "") {
- if (!exePath.EndsWith (".config"))
- map.ExeConfigFilename = exePath + ".config";
- else
- map.ExeConfigFilename = exePath;
+ if (exePath == null || exePath.Length == 0) {
+ map.ExeConfigFilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+ } else {
+ if (!Path.IsPathRooted (exePath))
+ exePath = Path.GetFullPath (exePath);
+ if (!File.Exists (exePath)) {
+ Exception cause = new ArgumentException ("The specified path does not exist.", "exePath");
+ throw new ConfigurationErrorsException ("Error Initializing the configuration system:", cause);
+ }
+ map.ExeConfigFilename = exePath + ".config";
}
break;
case ConfigurationUserLevel.PerUserRoaming:
}
return ConfigurationFactory.Create (typeof(ExeConfigurationHost), map, userLevel);
- }\r
-\r
-#if TARGET_JVM\r
- [MonoLimitation ("Supported only when the userLevel parameter is set to ConfigurationUserLevel.None. Other values are not supported because Environment.GetFolderPath method is not implemented.")]\r
-#endif\r
+ }
+
+#if TARGET_JVM
+ [MonoLimitation ("Supported only when the userLevel parameter is set to ConfigurationUserLevel.None. Other values are not supported because Environment.GetFolderPath method is not implemented.")]
+#endif
public static Configuration OpenExeConfiguration (ConfigurationUserLevel userLevel)
{
return OpenExeConfigurationInternal (userLevel, Assembly.GetEntryAssembly () ?? Assembly.GetCallingAssembly (), null);
}
/* invoked from System.Web */
- static IInternalConfigSystem ChangeConfigurationSystem (IInternalConfigSystem newSystem)
+ internal static IInternalConfigSystem ChangeConfigurationSystem (IInternalConfigSystem newSystem)
{
if (newSystem == null)
throw new ArgumentNullException ("newSystem");
lock (lockobj) {
+ // KLUDGE!! We need that when an assembly loaded inside an ASP.NET
+ // domain does OpenExeConfiguration ("") - we must return the path
+ // to web.config in that instance.
+ string t = newSystem.GetType ().ToString ();
+ if (String.Compare (t, "System.Web.Configuration.HttpConfigurationSystem", StringComparison.OrdinalIgnoreCase) == 0)
+ systemWebInUse = true;
+ else
+ systemWebInUse = false;
+
IInternalConfigSystem old = configSystem;
configSystem = newSystem;
return old;