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...
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.0.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
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:


Attachments
Test case (80.21 KB, application/zip)
2016-03-15 09:38 UTC, Prashant Cholachagudda
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 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:
Status:
VERIFIED FIXED

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

Or 

- Download and run the attached test case

# Using Xamarin.Forms version 2.1.0.6529
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 2.3.0.38-pre2 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.

Thanks..!
Comment 3 david gu 2016-07-05 20:29:53 UTC
I have update the Xamarin Forms to 2.3.0.107, but this issue still exist.
Comment 4 Parmendra Kumar 2016-07-07 11:53:39 UTC
I checked this issue with Xamarin.Forms 2.3.0.107 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.

Thanks.