Bug 53051 - Using attributes with Thickness in ResourceDictionary in App.xaml and using xaml precompiling crashes app
Summary: Using attributes with Thickness in ResourceDictionary in App.xaml and using x...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-03-04 08:48 UTC by Josha Munnik
Modified: 2017-03-14 18:51 UTC (History)
3 users (show)

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


Attachments
repro project (295.19 KB, application/x-zip-compressed)
2017-03-14 18:51 UTC, Jimmy [MSFT]
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:
RESOLVED FIXED

Description Josha Munnik 2017-03-04 08:48:05 UTC
When specifying Thickness with Left/Right/Top/Bottom attributes in a ResourceDictionary in App.xaml and enabling precompiling of xaml via [assembly: XamlCompilation(XamlCompilationOptions.Compile)] will crash the app on Android (tested on Samsung S7, not tested on iOS).

To reproduce:
- create a new Cross Platform Xamarin app using PCL
- add following to App.xaml:

        <ResourceDictionary>
            <!-- <Thickness x:Key="PageMargin">10,0,10,0</Thickness> -->
            <Thickness x:Key="PageMargin" Left="10" Right="10" Bottom="0" Top="0" />
        </ResourceDictionary>

- change MainPage.xaml, and add attributes to label:

           Margin="{StaticResource PageMargin}"
           BackgroundColor="Gray"
           HorizontalOptions="FillAndExpand"

Build and run on Android. 

Add [assembly: XamlCompilation(XamlCompilationOptions.Compile)] above namespace decleration in App.xaml.cs

Build and run on Android -> Crash while running InitializeComponent(); within the App constructor.

When using the first form to specify Thickness, everything works ok when using XamlCompilation.
Comment 1 Jimmy [MSFT] 2017-03-06 16:15:20 UTC
Thank you for filing this report! Let me try the steps you provided to see if can reproduce and confirm this issue. I will update the report accordingly.
Comment 2 Jimmy [MSFT] 2017-03-14 18:51:14 UTC
Created attachment 20319 [details]
repro project

I was able to reproduce this crash with the repro project I'm attaching with Forms 2.3.3.193. The app would crash on all platforms upon launching. On Android the debug output showed:

> 03-14 11:23:06.697 E/mono    ( 1788): Unhandled Exception:
> 03-14 11:23:06.697 E/mono    ( 1788): System.InvalidProgramException: Invalid IL code in XamlCTest.App:InitializeComponent (): IL_0050: callvirt  0x0a00000a


### Resolution status
I tested with Forms 2.3.4-pre4 and the crash no longer occurs so this issue appears to have been fixed. If you still experience this issue with Forms 2.3.4-pre4 or later please re-open this bug and attach an updated repro project.


### Version Tests
Forms 2.3.4-pre4    GOOD
Forms 2.3.3.193     BAD