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)

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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 9178 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

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.