Bug 9178 - Cannot cast from source type to destination type
Summary: Cannot cast from source type to destination type
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-01-02 05:50 UTC by Fred
Modified: 2013-07-02 05:59 UTC (History)
2 users (show)

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


Attachments
simple asp.net project (created with MonoDevelop) (5.33 KB, application/octet-stream)
2013-01-02 05:50 UTC, Fred
Details

Description Fred 2013-01-02 05:50:09 UTC
Created attachment 3152 [details]
simple asp.net project (created with MonoDevelop)

System.InvalidCastException thrown by System.Web.UI.WebControls.DataGrid.LoadViewState when clicking on a ButtonColumn and when some specific DataGrid properties are set at runtime.

It took me ages to track this one down.
 
For instance, System.Web.UI.WebControls.DataGrid.Font.Bold does raise the exception.
Some others as well, but not all.
For instance, System.Web.UI.WebControls.DataGrid.HeaderStyle.Font.Bold does not.

Tested on mono 2.10.9 on MacOSX either ASP.NET 2.0 or ASP.NET 4.0
Works as it should on Windows.

Simple ASP.NET test case attached.
Comment 1 Fred 2013-01-02 11:15:42 UTC
Same problem on mono 3.0.2 beta / MacOSX with the following supplemental error message:

Details: Non-web exception. Exception origin (name of application or object): System.Web.
Comment 2 Fred 2013-01-02 13:04:10 UTC
It seems to work with mono 2.6.7-5.1 on Debian 6 x64.
Might be a regression.
Comment 3 APS 2013-07-02 05:59:43 UTC
The error is still present in 3.0.7 but I think to have found the reason and to have fixed it modifying mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs LoadViewState method in this way:

if (pieces [9] != null)
	ControlStyle.LoadViewState (pieces [9]);

if (pieces [10] != null) {
	// IStateManager manager = (IStateManager) DataSourceColumns;
	// manager.LoadViewState (pieces [10]);
	object [] cols = (object []) pieces [10];
	foreach (object o in cols) {
		BoundColumn c = new BoundColumn ();
		((IStateManager) c).TrackViewState ();
		c.Set_Owner (this);
		((IStateManager) c).LoadViewState (o);
		DataSourceColumns.Add (c);
	}
}

and removing the following lines (if (pieces [9] != null) {....) till the end of the method.
I tested it and it seems to work. I'll provide a patch file ass soon as possible.

Note You need to log in before you can comment on or make changes to this bug.