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)

See Also:
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

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.

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