Bug 39636 - Cannot use XamlC with OnPlatform in resources, it throws System.InvalidCastException
Summary: Cannot use XamlC with OnPlatform in resources, it throws System.InvalidCastEx...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-03-15 09:38 UTC by Prashant Cholachagudda
Modified: 2018-07-16 20:37 UTC (History)
12 users (show)

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

Test case (80.21 KB, application/zip)
2016-03-15 09:38 UTC, Prashant Cholachagudda

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 Prashant Cholachagudda 2016-03-15 09:38:09 UTC
Created attachment 15404 [details]
Test case

Cannot use XamlC with OnPlatform in resources, the XF throws following exception (on both iOS and Android)

System.InvalidCastException: Specified cast is not valid.
  at xamlcomptest.MainView.InitializeComponent () [0x00172] in <filename unknown>:0
  at xamlcomptest.MainView..ctor () [0x00008] in /Users/prashantvc/Desktop items/Xamarin/309509/xamlcomptest/xamlcomptest/MainView.xaml.cs:12
  at xamlcomptest.App..ctor () [0x0000e] in /Users/prashantvc/Desktop items/Xamarin/309509/xamlcomptest/xamlcomptest/App.xaml.cs:14
  at xamlcomptest.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00007] in /Users/prashantvc/Desktop items/Xamarin/309509/xamlcomptest/iOS/AppDelegate.cs:17
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2966/58ba2bc3/source/maccore/src/UIKit/UIApplication.cs:77
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2966/58ba2bc3/source/maccore/src/UIKit/UIApplication.cs:61
  at xamlcomptest.iOS.Application.Main (System.String[] args) [0x00008] in /Users/prashantvc/Desktop items/Xamarin/309509/xamlcomptest/iOS/Main.cs:17

# Steps to reproduce 
- Create Xamarin.Forms project
- Setup XAML ResourceDictionary
- Define a value using OnPlatform
- Reference the value in XAML
- Enable XamlCompilation


- Download and run the attached test case

# Using Xamarin.Forms version
Comment 1 Jason Smith [MSFT] 2016-04-07 06:15:38 UTC
Should be fixed in 2.3.0-pre1
Comment 2 Rajneesh Kumar 2016-05-10 18:38:05 UTC
I have checked this issue with the XF and observed that this issue has been fixed and no longer exist with this version of XF. Now user is able to run attached test same successfully without any exception.

Screencast: http://www.screencast.com/t/MEfGL54en

This issue has been fixed, hence I am closing this issue.

Comment 3 david gu 2016-07-05 20:29:53 UTC
I have update the Xamarin Forms to, but this issue still exist.
Comment 4 Parmendra Kumar 2016-07-07 11:53:39 UTC
I checked this issue with Xamarin.Forms and using attached sample in bug description. and this issue is working fine at my end.

@David, Could you please let me know some more information regarding your issue or Please file a separate bug for the same.