Bug 55469 - Invalid Cast Exception when converting NSObject to WebSkriptObject
Summary: Invalid Cast Exception when converting NSObject to WebSkriptObject
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 3.2.0 (15.1)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-04-21 13:45 UTC by Gerhard Herbert
Modified: 2017-07-10 16:33 UTC (History)
4 users (show)

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

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Gerhard Herbert 2017-04-21 13:45:36 UTC
After upgrading Xamarin to the latest version (Version 6.3 build 863) casting an NSObject to WebSkriptObject throws an InvalidCastException. However in release-mode (debug info set to 'none') the cast works as expected.

With the previous version of Xamarin everything was ok. Operating System: Mac 10.12.4 It works after downgrading Xamarin.Mac from 3.2 to 3.0.
Comment 1 Chris Hamons 2017-04-21 13:54:52 UTC
This is very likely due to the change we made in default configuration in Release mode.

It is mentioned here:


But the short answer is that we default to the static registrar in Release configuration. However, there are a few known cases, such as some WebKit APIs, where the dynamic registrar is required.

Try going into your project options -> mac build -> Additional MMP arguments and adding:


I'm not sure if we can do much on our end, except possibly scanning for a "bad" list of APIs in your application during package. 

A small sample showing the issue would be useful though.
Comment 2 Gerhard Herbert 2017-04-24 06:52:56 UTC
As mentioned before, the Release-configuration works as expected, the Debug-configuration throws the exception.
Comment 3 Chris Hamons 2017-04-24 13:30:48 UTC
My mistake, I read it backwards. Let's see if the reverse is true:

--registrar:static in Debug mmp args.
Comment 4 Manuel de la Peña [MSFT] 2017-06-07 10:30:41 UTC
@Gerhard can you please provide an answer to @chris
Comment 5 Vincent Dondain [MSFT] 2017-07-10 16:33:24 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!