[Mono-list] issue with Application.Lock

Peter Hagen peter at wingsofdeath.net
Mon Feb 28 05:31:14 EST 2011


Hi

today I installed the mono 2.10.1 on my server, and it seems to run very
nicely. But I found a issue with the project NeatUpload, which I'm not
sure if its a bug from them, or maybe in Mono. The application throws a
exception:

The current thread has not entered the lock in read mode
Description: HTTP 500. Error processing request.

Stack Trace:

System.Threading.SynchronizationLockException: The current thread has not entered the lock in read mode
  at System.Threading.ReaderWriterLockSlim.ExitReadLock () [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplicationState.Get (System.String name) [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplicationState.get_Item (System.String name) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.InProcUploadStateStoreProvider.Load (System.String postBackID) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.InProcUploadStateStoreProvider.MergeAndSave (Brettle.Web.NeatUpload.UploadState uploadState) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.AdaptiveUploadStateStoreProvider.MergeAndSave (Brettle.Web.NeatUpload.UploadState uploadState) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.UploadStateStore.MergeAndSave (Brettle.Web.NeatUpload.UploadState uploadState) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.UploadStateStore.UploadState_Changed (System.Object sender, System.EventArgs args) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.UploadState.OnChanged () [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.UploadState.set_Status (UploadStatus value) [0x00000] in <filename unknown>:0 
  at Brettle.Web.NeatUpload.UploadHttpModule.Application_ResolveRequestCache (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication+<RunHooks>c__Iterator2.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication+<Pipeline>c__Iterator3.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication.Tick () [0x00000] in <filename unknown>:0 

________________________________________________________________________
Version information: Mono Runtime Version: 2.10.1 (tarball Mon Feb 28
09:35:03 CET 2011); ASP.NET Version: 2.0.50727.1433

I checked the source of NeatUpload code, and here is what they do:

	public class InProcUploadStateStoreProvider : UploadStateStoreProvider
	{
       public override string Description { get { return "Stores
UploadState objects in the HttpApplicationState of the current
process."; } }

		private static string KeyPrefix = "NeatUpload_InProcUploadState_";

		public override UploadState Load(string postBackID)
		{
			string key = KeyPrefix + postBackID;
			return Application[key] as UploadState;
		}

		public override void MergeAndSave(UploadState uploadState)
		{
			string key = KeyPrefix + uploadState.PostBackID;
			Application.Lock();
			try
			{
				UploadState storedUploadState = Load(uploadState.PostBackID);
				Merge(uploadState, storedUploadState);
				Application[key] = uploadState;
			}
			finally
			{
				Application.UnLock();
			}
		}

        private HttpApplicationState Application
        {
            get
            {
                HttpContext ctx = HttpContext.Current;
                if (ctx != null)
                    return ctx.Application;
                if (ThreadStaticApplication != null)
                    return ThreadStaticApplication;
                throw new
NullReferenceException("ThreadStaticApplication == null");
            }
        }

I removed some not important code here. To solve the issue changed the
code in MergeAndSave() to :

	public override void MergeAndSave(UploadState uploadState)
	{
		string key = KeyPrefix + uploadState.PostBackID;
		
		
		HttpApplicationState app = Application;
		lock (app) {
			UploadState storedUploadState = Load(uploadState.PostBackID);
			Merge(uploadState, storedUploadState);
			Application[key] = uploadState;
		}
	}

And this seems to work nicely. But, could this be a bug in Mono? I
thought I better ask first, cause I'm not familiar with using
Application.Lock in this situation. In other words, I never use it, so
my workaround should be not problem.

With kind regards,

Peter


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20110228/c602ef5d/attachment-0001.html 


More information about the Mono-list mailing list