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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 24308 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

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