The section mapping system wasn't being initialized and used properly since some ifdefs had
been left in the source code. This caused a null reference exception while trying to perform
some HTTP requests and, as the result, broke Xamarin Studio activation.
As suggested by Marek Habersack, instead of catching
SynchronizationLockException in the case that the lock wasn't
acquired, we now have a boolean that indicates if it was
acquired or not, so we can act on it on the finally{} block.
System.Web.ConfigurationManager had a cache which didn't have any max limit,
therefore when using Restful URIs in ASP.NET (like having some variable
parameter in the virtual path, i.e. /user/{userId}/tracks, where {userId}
is a variable Integer) this was very likely to cause a leak which would
end up causing troubles, like an InvalidCastException thrown by
HttpApplication::PreStart()
(Read operations in the cache now cause a write operation on the cache
object, so all sectionCache lock-read usages are converted to lock-write.)
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=5598
System.Web.ConfigurationManager had a cache which didn't have any max limit,
therefore when using Restful URIs in ASP.NET (like having some variable
parameter in the virtual path, i.e. /user/{userId}/tracks, where {userId}
is a variable Integer) this was very likely to cause a leak which would
end up causing troubles, like an InvalidCastException thrown by
HttpApplication::PreStart()
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=5598
Following is a step by step guide to create a testing project:
(1) Create an ASP.NET project in MonoDevelop
(2) Create a folder "base"
(3) Create two subfolders called "sub1" and "sub2" inside of "base"
(4) Create a web.config file in both sub folders "sub1" and "sub2" and enter the following code:
<configuration>
<appSettings>
<add key="myText" value="src=sub1"/>
</appSettings>
</configuration>
Set the "value=" element to the appropriate value of the corresponding sub folder.
(5) Enter the following code in Default.aspx.cs
public void Page_Load(object sender, EventArgs args)
{
//c2.ConfigPath contains wrong path
Configuration c1 = WebConfigurationManager.OpenWebConfiguration("~/base/sub1");
Configuration c2 = WebConfigurationManager.OpenWebConfiguration("~/base/sub2");
//myText_sub2 refers to the wrong AppSettings entry
KeyValueConfigurationElement myText_sub1 = (KeyValueConfigurationElement)c1.AppSettings.Settings["myText"];
KeyValueConfigurationElement myText_sub2 = (KeyValueConfigurationElement)c2.AppSettings.Settings["myText"];
}
* HttpRuntime.cs: disable filesystem watchers on appdomain shutdown and refuse to process
requests while the current AppDomain is unloading
* HttpApplicationFactory.cs: if the current AppDomain is unloading, ignore FileSystemWatcher
notifications
* WebConfigurationManager.cs: work around a deadlock issue when entering a ReaderWriterLockSlim
upgradeable read lock very early during ASP.NET runtime/AppDomain initialization. Every few runs
the attempt would lock up and since adding a section to cache is not a critical operation we can
afford timing the lock out in this case. The lockup is probably due to the fact that RWLS is using
thread local storage to store the current thread's lock status and it may happen that the TLS is
not cleared during thread object finalization (see metadata/threads.c, the start_wrapper function)
The patch removes a small race condition where a boolean flag is set after acquiring a lock to
indicate to code executing in the finally {} block that it should release the lock. The boolean
variable is now removed and the lock is released unconditionally. It carries a potential to
throw an exception when the lock is not held, but it's better than to fail to release it and
lead the application to a deadlock.
WebConfigurationHost now supports one more parameter passed to it in InitForConfiguration -
a boolean telling whether the configuration being initialized belongs to another app. If it is
true then the virtual path passed to InitForConfiguration is used as the application virtual
path. This has the effect that IsDefinitionAllowed doesn't throw an exception when a configuration
element with the MachineToApplication level is parsed.
WebConfigurationManager.FindWebConfig checks whether the path passed to it belongs to this application
which allows the mechanism described in the first paragraph to work.
Author: Marek Habersack <[email protected]>
Date: Sat Mar 6 03:37:53 2010 +0100
2010-03-06 Marek Habersack <[email protected]>
* CompilerCollection.cs: in the 4.0 profile, the latest C#
standard is the compiler's default.
2010-03-06 Marek Habersack <[email protected]>
* CSharpCodeCompiler.cs: in the 4.0 profile, the latest C#
standard is the default one.
2010-03-06 Marek Habersack <[email protected]>
* RequestValidatorTestGenerated.cs: added
* RequestValidator.cs: added
2010-03-06 Marek Habersack <[email protected]>
* TestWorkerRequest.cs: added overloads of GetRawUrl and
GetUriPath which make sure that the returned paths do not contain
more than one leading / character.
* TestRunItem.cs: added new TestRunData property - to contain
per-appdomain test run data.
* TestCallback.cs: added a TestRunItem parameter.
* StandaloneTest.cs: runner object is created for each test item
now.
Added test progress feedback.
* ITestRunner.cs: added two properties, TestRunData - to return
collected test result data, if any, and Domain which returns the
current AppDomain.
2010-03-06 Marek Habersack <[email protected]>
* RequestValidatorTest.cs: added
2010-03-06 Marek Habersack <[email protected]>
* HttpRequest.cs: cache RawUrl value.
Added new internal property, PathNoValidation, which returns
request path without validating it.
Implemented 4.0 extensible validation.
* HttpApplication.cs: Pipeline () validates the request path, if
new validation mode is enabled, before doing anything else.
Added a generic LoadType overload which checks whether the loaded
type, if any, derives from the type specified in the method's
specialization.
2010-03-06 Marek Habersack <[email protected]>
* RequestValidator.cs: added
* RequestValidationSource.cs: added
2010-03-06 Marek Habersack <[email protected]>
* WebConfigurationManager.cs: do not use Request.Path - it may
fail because of invalid web.config file, use
Request.PathNoValidation instead.
* VersionConverter.cs: added
* PropertyHelper.cs: added a Version converter helper.
* HttpRuntimeSection.cs: added 4.0 properties -
RequestPathInvalidCharacters, RequestValidationType and
RequestValidationMode.
svn path=/trunk/mcs/; revision=153172
* BuildManager.cs: do less work in the static constructor
2010-03-04 Marek Habersack <[email protected]>
* RuntimeHelpers.cs: added. Contains methods moved here from
HttpRuntime, so that initialization sequence of various objects is
independent of HttpRuntime.
2010-03-04 Marek Habersack <[email protected]>
* HttpRuntime.cs: do less work in the static constructor. Most of
the code was moved to System.Web.Util.RuntimeHelpers. Properties
which have been moved: MonoVersion, RunningOnWindows,
CaseInsensitive, IsDebuggingEnabled
Also:
- hushed some compiler warnings
- various classes now use RuntimeHelpers instead of HttpRuntime
svn path=/trunk/mcs/; revision=153038
* WebConfigurationManager.cs: GetSection properly handles looking
up and caching of <location> instances. Part of fix for bug
#568441
* WebConfigurationHost.cs: GetConfigPathFromLocationSubPath
calculatesthe path relative to the current config file path. Part
of fix for bug #568441
2010-01-09 Marek Habersack <[email protected]>
* VirtualPathUtility.cs: small optimizations for GetDirectory
2010-01-09 Marek Habersack <[email protected]>
* ConfigurationLocation.cs: trailing / characters are removed from
the path.
* Configuration.cs: instances created for locations inherit
ConfigPath from their containing document.
Host.GetConfigPathFromLocationSubPath must be called with current
instance's configPath, not LocationConfigPath.
Locations are sought for using paths relative to the current
instance's configPath, not to the root path.
All of the above is part of fix for bug #568441
svn path=/trunk/mcs/; revision=149262
* WebConfigurationManager.cs: use an rw lock to protect access to
sectionCache. This is now necessary as the save handler clears the
cache.
svn path=/trunk/mcs/; revision=146525
* TemplateParser.cs: AddImports is called from LoadConfigDefaults
so that it reads configuration from the correct .config file (it
needs to be called after this.VirtualPath has been
initialized). Fixes an issue with MVC apps which put configuration
in Views/web.config etc. Fixes bug #552457
* ControlBuilder.cs, Page.cs: system.web/pages section is not
confined to the top-level web.config
2009-11-10 Marek Habersack <[email protected]>
* WebConfigurationManager.cs: path passed to OpenWebConfiguration
from GetSection does not come from FindWebConfig.
2009-11-10 Marek Habersack <[email protected]>
* BaseCompiler.cs: parser.Imports is a Dictionary <>/Hashtable
now.
* AspComponentFoundry.cs: system.web/pages section is not confined
to the top-level web.config
svn path=/trunk/mcs/; revision=145831
* WebConfigurationManager.cs: there's no need to cache sections by
_file_ path - using section name and web.config path is more than
enough and it reduces the number of cache entries
considerably. Fixes bug #550730
svn path=/trunk/mcs/; revision=145721
* WebConfigurationManager.cs: GetSection doesn't perform string +
char + string concatenation to generate section cache key (by
Gonzalo Paniagua Javier) which gives an enormous performance boost
(processing time for mojoportal's default.aspx went down from
2.65s to 107ms on average). The key generation is performed
without any kind of string operation right now (except for
GetHashCode on 3 strings).
GetSectionCacheKey is called only once and sectionCache became a
dictionary.
svn path=/trunk/mcs/; revision=143611
* WebConfigurationManager.cs: GetSection does not use
FindWebConfig to get the virtual path to open configuration for -
doing so would make the configuration system ignore <location>
sections. Fixes bug #482181
svn path=/trunk/mcs/; revision=140375
* WebConfigurationManager.cs: another approach to suppressing
application reloads after the app writes to its root web.config
file. Leaving the previous code in place to get more
protection. It's a kludge, but it's the best option to avoid
all the races caused by System.Configuration+FileSystemWatcher
without rewriting large parts of System.Configuration (and
System.Web.Configuration). Fixes bug #522017
2009-07-15 Marek Habersack <[email protected]>
* Configuration.cs: explicitly flush the stream when writing XML
data. Part of fix for bug #522017
2009-07-15 Marek Habersack <[email protected]>
* HttpApplicationFactory.cs: added internal methods to
enable/disable specific watchers. Part of fix for bug #522017
svn path=/trunk/mcs/; revision=137951
* WebConfigurationManager.cs: added support for suppressing
application reload when the main config file is written to from
application.
* WebConfigurationHost.cs: added minimal implementation of
WriteCompleted, which checks if there's need to suppress
application reload.
2009-07-14 Marek Habersack <[email protected]>
* ConfigurationSaveEventArgs.cs, ConfigurationSaveEventHandler.cs:
added
* Configuration.cs: added two internal events - SaveStart and
SaveEnd. They are used by System.Web's configuration system to
suppress application reloads when configuration is modified and
saved from within a web application. It is necessary to use events
since there is no guarantee the web application will use
WebConfigurationManager (and thus WebConfigurationHost) for
writing.
2009-07-14 Marek Habersack <[email protected]>
* System.Configuration.dll.sources: added
System.Configuration/ConfigurationSaveEventArgs.cs
System.Configuration/ConfigurationSaveEventHandler.cs
2009-07-14 Marek Habersack <[email protected]>
* AssemblyInfo.cs: added InternalsVisibleTo for System.Web
2009-07-14 Marek Habersack <[email protected]>
* HttpApplicationFactory.cs: OnFileChanged doesn't reload
application if reload suppression is active.
svn path=/trunk/mcs/; revision=137847
* WebConfigurationHost.cs: null means MachineToApplication.
* WebConfigurationManager.cs: when caching configuration and sections,
use the configuration file directory instead of the incoming request
path.
svn path=/trunk/mcs/; revision=137632
* VirtualPathUtility.cs: IsValidVirtualPath no longer uses
WebConfigurationManager.GetSection to retrieve the verification
setting. Instead, the setting is retrieved in the static
constructor.
* HttpRequest.cs: ApplyUrlMapping must not use
WebConfigurationManager.GetSection as it would cause a recursive
call loop. Code to detect whether url mappings are in effect has
been moved to a static constructor.
2009-06-05 Marek Habersack <[email protected]>
* Page.cs: InitializeTheme uses WebConfigurationManager.GetSection
to retrieve page theme name. GetWebApplicationSection cannot be
used because the system.web/pages section is valid also in
subdirectories. Fixes bug #510302
2009-06-05 Marek Habersack <[email protected]>
* WebConfigurationManager.cs: OpenWebConfiguration caches
configurations with a key generated from all the parameters passed
to it, not just from path.
Added internal GetSection method which takes HttpContext as its
third parameter - used in calling OpenWebConfiguration.
FindWebConfig is no longer used in GetSection - it breaks handling
of <location> elements in config files. Fixes bug #510302
svn path=/trunk/mcs/; revision=135558
* WebConfigurationManager.cs: added code in the static constructor
to enable retrieving application settings via
ApplicationSettingsBase from within asp.net applications. Fixes
bug #491531
* ApplicationSettingsConfigurationFileMap.cs: added.
2009-04-03 Marek Habersack <[email protected]>
* CustomizableFileSettingsProvider.cs: added a way for System.Web
to specify path to the current Web.config. Fixes bug #491531
svn path=/trunk/mcs/; revision=130909
* WebConfigurationManager.cs: A better version of the previous
GetSection fix. Right now the method searches for directories
containing web.config and uses them, if found, to open the web
configuration. If no web.config is found, web configuration is
opened for the root application directory.
* WebConfigurationHost.cs: made GetWebConfigFileName internal
static, so that code can be reused from WebConfigurationManager.
svn path=/trunk/mcs/; revision=122124
* NunitWeb/Makefile (NunitWeb.dll): added NunitWeb/CustomSection.cs
* NunitWebResources/CustomSectionEmptyCollection.aspx: added
2008-12-23 Marek Habersack <[email protected]>
* WebConfigurationManagerTest.cs: added new test.
2008-12-23 Marek Habersack <[email protected]>
* CustomSection.cs: added. Implementation of custom configuration
elements for WebConfigurationManager tests.
2008-12-23 Marek Habersack <[email protected]>
* Web.mono.config: added CustomTags section definition, used in
WebConfiguratioManager tests.
2008-12-23 Marek Habersack <[email protected]>
* WebConfigurationManager.cs: GetSection should call
OpenWebConfiguration using the actual directory path, not a file
path. If it fails to do so, System.Configuration may treat the
top-level Web.config file as a child one which, in turn, in
certain circumstances will lead to duplicate keys inserted in
collections.
2008-12-23 Marek Habersack <[email protected]>
* Makefile (TEST_RESOURCE_FILES): added Test/mainsoft/NunitWebResources/CustomSectionEmptyCollection.aspx
* System.Web_test.dll.sources: added mainsoft/NunitWeb/NunitWeb/CustomSection.cs
svn path=/trunk/mcs/; revision=122024
* HttpRuntime.cs: SettingsMappingManager has been moved to
Mono.Web.
2008-03-01 Marek Habersack <[email protected]>
* WebConfigurationManager.cs: SettingsMappingManager has been
moved to Mono.Web.dll
2008-03-01 Marek Habersack <[email protected]>
* Makefile: added a dependency on Mono.Web.dll
* System.Web.dll.sources: removed SystemSettingsMapper public APIs
and moved them to the Mono.Web assembly.
2008-03-01 Marek Habersack <[email protected]>
* AssemblyInfo.cs: added
2008-03-01 Marek Habersack <[email protected]>
* ISectionSettingsMapper.cs, MembershipSectionMapper.cs,
RoleManagerSectionMapper.cs, SettingsMapping.cs,
SettingsMappingManager.cs, SettingsMappingWhat.cs: moved to here
from System.Web
2008-03-01 Marek Habersack <[email protected]>
* Mono.Web.dll.sources: added
* Makefile: added
svn path=/trunk/mcs/; revision=97035
* WebConfigurationManager.cs: hashtable can contain a key with a
null value, avoid adding duplicate keys in such cases.
svn path=/trunk/mcs/; revision=96532