Bug 55918 - Invalid cast exception when converting Dom objects to DomHtml objects
Summary: Invalid cast exception when converting Dom objects to DomHtml objects
Status: REOPENED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) (show other bugs)
Version: 3.2.0 (15.1)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-03 15:08 UTC by Harry Williams
Modified: 2017-05-16 00:38 UTC (History)
3 users (show)

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


Attachments
Sample project showing issue (346.63 KB, application/zip)
2017-05-05 10:17 UTC, Harry Williams
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 55918 on Developer Community or GitHub 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: Developer Community HTML or GitHub Markdown
  • 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:
REOPENED

Description Harry Williams 2017-05-03 15:08:39 UTC
Trying to run either line of code in the following method results in an invalid cast exception:

public override void FinishedLoad(WebView sender, WebFrame forFrame)
{
var dom = (DomHtmlDocument)forFrame.DomDocument;
var node = (DomHtmlElement)forFrame.DomDocument.GetElementById("element_id");
}

Unhandled Exception:
System.InvalidCastException: Specified cast is not valid.
  at WebTester.FrameLoadDelegate.FinishedLoad (WebKit.WebView sender, WebKit.WebFrame forFrame) [0x0000c] in /Users/hw/Projects/Restore/WebTester/WebTester/MainWindowController.cs:57 
  at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/4466/a04678c2/source/xamarin-macios/src/AppKit/NSApplication.cs:99 
  at WebTester.MainClass.Main (System.String[] args) [0x00007] in /Users/hw/Projects/Restore/WebTester/WebTester/Main.cs:10 
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Specified cast is not valid.
  at WebTester.FrameLoadDelegate.FinishedLoad (WebKit.WebView sender, WebKit.WebFrame forFrame) [0x0000c] in /Users/hw/Projects/Restore/WebTester/WebTester/MainWindowController.cs:57 
  at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/4466/a04678c2/source/xamarin-macios/src/AppKit/NSApplication.cs:99 
  at WebTester.MainClass.Main (System.String[] args) [0x00007] in /Users/hw/Projects/Restore/WebTester/WebTester/Main.cs:10 

This code works correctly before upgrade to latest release

Version information:

Xamarin Studio Community
Version 6.3 (build 863)

Xamarin.Mac
Version: 3.2.0.175 (Xamarin Studio Community)
Comment 1 Chris Hamons 2017-05-03 15:12:29 UTC
Does this fail in Release mode only?

Maybe the change in default registrar mode (https://developer.xamarin.com/releases/mac/xamarin.mac_3/xamarin.mac_3.2/#Release_Mode_MMP_Default_Changes) changed things?

You can test this by adding --registrar:dynamic to your Project Options -> Mac Build -> Additional MMP Args section.
Comment 2 Harry Williams 2017-05-04 08:48:49 UTC
No, this error happens in debug mode
Comment 3 Chris Hamons 2017-05-04 15:28:53 UTC
What is the type of the return that is not matching the cast?

I need more code or a sample to dig into this.
Comment 4 Harry Williams 2017-05-05 10:17:23 UTC
Created attachment 21971 [details]
Sample project showing issue
Comment 5 Sebastien Pouliot 2017-05-16 00:38:20 UTC
Re-opening, Sample attached.