I get the following error when using the ImageResizer module on Mono in Linux:
Server Error in '/' Application
Argument is out of range. Parameter name: date
Description: HTTP 500. Error processing request.
Stack Trace:
System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: date
at System.Web.HttpCachePolicy.SetLastModified (DateTime date) [0x00046] in /build/src/mono-2.10.8/mcs/class/System.Web/System.Web/HttpCachePolicy.cs:225
at ImageResizer.Caching.ResponseHeaders.DefaultApplyToResponseMethod (IResponseHeaders headers, System.Web.HttpContext context) [0x00000] in <filename unknown>:0
at ImageResizer.Plugins.Basic.NoCacheHandler.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator6.MoveNext () [0x00dad] in /build/src/mono-2.10.8/mcs/class/System.Web/System.Web/HttpApplication.cs:1368
at System.Web.HttpApplication.Tick () [0x00000] in /build/src/mono-2.10.8/mcs/class/System.Web/System.Web/HttpApplication.cs:932
Version information: Mono Runtime Version: 2.10.8 (tarball Sat Dec 31 02:07:23 UTC 2011); ASP.NET Version: 4.0.30319.1
Here is the debug sheet:
Image resizer diagnostic sheet 07/09/2012 14:15:41
3 Issues detected:
(Warning): To potentially see additional errors here, perform an image resize request.
(Warning): UrlAuthorizationModule.CheckUrlAccessForPrincipal is not supported on this runtime (are you running Mono?)
It may be possible for users to bypass UrlAuthorization rules you have defined for your website, and access images that would otherwise be protected. If you do not use UrlAuthorization rules, this should not be a concern. You may also re-implement your security rules by handling the Config.Current.Pipeline.AuthorizeImage event.
(Warning): NoCache is only for development usage, and cannot scale to production use.
Add DiskCache or CloudFront for production use
You are not using any paid bundles.
Registered plugins:
ImageResizer.Plugins.Basic.DefaultEncoder
ImageResizer.Plugins.Basic.NoCache
ImageResizer.Plugins.Basic.ClientCache
ImageResizer.Plugins.Basic.Diagnostic
ImageResizer.Plugins.Basic.SizeLimiting
ImageResizer.Plugins.MvcRoutingShim.MvcRoutingShimPlugin
Configuration:
<resizer>
<pipeline fakeExtensions=".ashx" />
<plugins>
<add name="MvcRoutingShim" />
</plugins>
</resizer>
Accepted querystring keys:
quality, format, thumbnail, maxwidth, maxheight, width, height, w, h, scale, stretch, crop, cropxunits, cropyunits, page, bgcolor, rotate, flip, sourceFlip, sFlip, sRotate, borderWidth, borderColor, paddingWidth, paddingColor, ignoreicc, frame, useresizingpipeline, cache, process, margin, anchor, dpi, mode, zoom,
Accepted file extensions:
bmp, gif, exif, png, tif, tiff, tff, jpg, jpeg, jpe, jif, jfif, jfi,
Environment information:
Running Apache on Unix 2.6.39.2 and CLR 4.0.30319.1
Trust level: Unrestricted
OS bitness:
Executing assembly: /usr/bin/mono
IntegratedPipeline: False
Loaded assemblies:
System.Runtime.Caching Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Messaging Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Transactions Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
Mono.Data.Tds Assembly: 4.0.0.0
Mono.Security Assembly: 4.0.0.0
System.Security Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
Mono.CSharp Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
App_global.asax_199cffe9 Assembly: 0.0.0.0
Microsoft.Web.Infrastructure Assembly: 1.0.0.0 File: 1.0.20105.407
dotless.Core Assembly: 1.3.0.3 File: 1.3.0.3 Info: 1.3.0.3
System.Web.WebPages.Razor Assembly: 1.0.0.0 File: 1.0.20105.407
System.Web.WebPages.Deployment Assembly: 1.0.0.0 File: 1.0.20105.407
System.Web.Razor Assembly: 1.0.0.0 File: 1.0.20105.407
ImageResizer Assembly: 3.2.3.302 File: 3.2.3.302 Info: 3-2-beta-3 Commit: 245e873
ImageResizer.Mvc Assembly: 3.2.3.302 File: 3.2.3.302 Info: 3-2-beta-3 Commit: 245e873
System.Web.WebPages Assembly: 1.0.0.0 File: 1.0.20105.407
System.Web.Mvc Assembly: 3.0.0.0 File: 3.0.20105.0
System.Web.Routing Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Web.Helpers Assembly: 1.0.0.0 File: 1.0.20105.407
System.Web.Abstractions Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Web.ApplicationServices Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Data.Linq Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Web.DynamicData Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.ComponentModel.DataAnnotations Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Xml.Linq Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Data.DataSetExtensions Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Web.Extensions Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Core Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.ServiceModel.Web Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 3.5.594.0
System.ServiceModel Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Xaml Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Runtime.Serialization Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.IdentityModel Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.EnterpriseServices Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Drawing Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Web.Services Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Data Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
Microsoft.CSharp Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
Mono.Posix Assembly: 4.0.0.0
Mono.WebServer2 Assembly: 0.4.0.0
mod-mono-server4 Assembly: 2.10.2.0
Mono.Web Assembly: 4.0.0.0 Info: 0.0.0.1
System.Xml Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Configuration Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
System.Web Assembly: 4.0.0.0 File: 4.0.0.0 Info: 0.0.0.1
mscorlib Assembly: 4.0.0.0 File: 4.0.30319.1 Info: 4.0.30319.1
Any idea what could be going wrong here?
This is technically a bug in Mono – Both .NET 2.0 and .NET 4.0 convert the date to universal time before performing the conversion, while mono compares it to the local server time, failing to even normalize the two variables to ensure they have matching time zones.
Mono See code
.NET (both V2 and V4) (Use ILSpy, search HttpCachePolicy with System.Web loaded)
Or, click this link to see the disassembly.
Psuedocode for SetLastModified(DateTime date):
Calling code (ImageResizer), /Core/Caching/ResponseHeaders.cs
Finding a workaround to this that won’t break something isn’t very simple. MS SQL provides LastModified values in un-specified time zones, while filesystems provide UTC but can be in the future if they’re from a remote server.
Since incoming DateTime values often don’t include a timezone flag, normalization is very important.
Converting to UTC, testing, converting back to local, testing, then assigning might be a valid workaround.
I suggest editing /Core/Caching/ResponseHeaders.cs, method DefaultApplyToResponseMethod to use the following statement
Please let me see if you notice a flaw in the logic; if I it works for you and passes the beta test it might be integrated into a future release.