martes, 27 de enero de 2009

MONO Formview/ObjectDataSourceView Bug?. Why some of the sections of my website Dissapear?

UPDATE : MONO Has Fixed this Bug in the 2.4 release, at least it seems to be fixed looking at the source code

But it seems to fail when the result is null because it returns a new Object collection with a null element wich seems to be wrong, so this patch could still apply under some circunstances

Well some days ago, while we’re developing our current project release using MONO 1.9.1, MONO 2.0 were released. It was including a lot of bugfixes and new features. So now we were able to compile the application in Linux without make any modification. We were really happy.

But our happiness was futile. Suddenly we realize that some portions of the Website were  not been rendered. We review the rendered code and realized that the formviews were not been rendered properly.

The Gridviews and other ASP.NET controls were rendering good, but, not the formviews. As we had to continue with the project release, we decide to turn back to MONO 1.9.1. At the end of the past Sprint, we decide to rertun and investigate why the the Formviews were not rendering.

First we were suspecting that it could be maybe a Viewstate Issue, (When we turned off the viewstate for the formview controls in MONO 1.9.1 they were not rendered also, turning the viewstate on solved the issue). But turning on or off the viewstate in MONO 2.0.x had no effect. The formview were still not rendered.

So, after some time of digging into the code, creating our custom Formview controls that inherited the ASP.NET Formview, overriding some methods and using the Response as Console for debugging (God! Mono needs a Debugger!) we found the issue.

So, here is:

The problem is located at the ExecuteSelect Method of the ObjectDataSourceView Class that is located in this path inside the MONO Source directory:

mono-2.2\mcs\class\System.Web\System.Web.UI.WebControls\ObjectDataSourceView.cs

(The MONO sources can be obtained from this location)

the method has this lines of code that could be wrong:

if (result is IEnumerable)
return (IEnumerable) result;
else
return new object[] {};

As you can see when you have methods that return only a single instance of an entity, and those methods are used as the SelectMethods of the ObjectDataSource Controls, the ExecuteSelect will consider they’re not IEnumerable instances so it will return an Empty collection, causing that the Formview Controls render nothing at the Aspx pages.

the correct code should be:

if (result is IEnumerable)
return (IEnumerable) result;
return (result != null)? new object [] { result } : new object[] {};

as you can see, now only if the result is null will be returned an empty collection otherwise a collection with exactly one element is returned.

So doing that modification, and recompiling the MONO Sources you could make your Formview Controls work properly again.

I reported the bug, but I’m not so sure if that is really a bug, (because maybe it is intended to work like that in the specs…) or if it will be solved soon by the MONO team.

Well, here is some useful information.

Details of the Bug, and some comments about it:

http://go-mono.com/forums/#nabble-td21435835

To re compile MONO Sources, after do the code change:

http://blog.palehorse.net/2008/11/06/my-adventures-installing-mono-20-on-centos-4-to-work-with-apache-via-mod_mono/

Good Luck, Hopely this could help someone else!

No hay comentarios: