Bug 24308 - System.NullReferenceException after access to ConfigurationManager
Summary: System.NullReferenceException after access to ConfigurationManager
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-11-06 09:21 UTC by damirainullin
Modified: 2014-11-06 09:24 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description damirainullin 2014-11-06 09:21:42 UTC
I use a simple console application. OS Ubuntu 14.04, Mono JIT compiler version 3.10.0
I change the HttpContext.Current property and try to get ConfigurationManager.AppSettings["some-setting"] field.

using System;
using System.Web;
using System.IO;
using System.Configuration;

namespace HttpContextCurrent
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			try
			{
			    HttpContext.Current = new HttpContext(
					new HttpRequest("some-filename", "http://www.bing.com/", string.Empty),
				    new HttpResponse(new StringWriter()));

				var someSettings = ConfigurationManager.AppSettings["some-setting"];
			}
			catch(Exception ex)
			{
				Console.WriteLine (ex.ToString());
			}
		}
	}
}

After this I catch NullReferenceException with next stack trace:

System.NullReferenceException: Object reference not set to an instance of an object
  at System.Web.Configuration.WebConfigurationHost.InitForConfiguration (System.String& locationSubPath, System.String& configPath, System.String& locationConfigPath, IInternalConfigRoot root, System.Object[] hostInitConfigurationParams) [0x00000] in <filename unknown>:0 
  at System.Configuration.InternalConfigurationSystem.InitForConfiguration (System.String& locationConfigPath, System.String& parentConfigPath, System.String& parentLocationConfigPath) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x00000] in <filename unknown>:0 
  at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) [0x00000] in <filename unknown>:0 
  at System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration (System.String path, System.String site, System.String locationSubPath, System.String server, System.String userName, System.String password, Boolean fweb) [0x00000] in <filename unknown>:0

Note You need to log in before you can comment on or make changes to this bug.