Bug 49228 - XAMLC NRE when x:Static is used on a const defined in seperate assembly
Summary: XAMLC NRE when x:Static is used on a const defined in seperate assembly
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2016-12-07 14:22 UTC by John Miller [MSFT]
Modified: 2017-03-16 01:09 UTC (History)
4 users (show)

See Also:
Tags: AC XamlC
Is this bug a regression?: ---
Last known good build:


Attachments
Sample Project (36.17 KB, application/zip)
2016-12-07 14:22 UTC, John Miller [MSFT]
Details

Description John Miller [MSFT] 2016-12-07 14:22:10 UTC
Created attachment 18810 [details]
Sample Project

** Overview **:

The following scenario causes a null reference exception when XAMLC is used in 2.3.3 at compile time:

// In AppProject1 and has a reference to LibraryProject1
> <Label Text="{x:Static constants2:Globals.AppName}"/>

Where `constants2` is a namespace from another separate referenced library project. 

// In LibraryProject1
> public class Globals
> {
>    public const string AppName = "My Xamarin Forms App 2";
> }

This results in a null reference exception for Globals.AppName.

** Steps to Reproduce **

1. Open the attached project in VS
2. Build the XFApp project

** Actual Results **:

> Object reference not set to an instance of an object.	XFApp	<path>\XFApp\XFApp.Views.MainPage.xaml		

Occasionally, I was getting an error that the XAMLC task failed unexpectedly. However, Rebuilding usually surfaced this NRE.

** Expected Results **:

No NRE at compile time.

** Additional Information **:

Downgrading to the project back to Forms 2.3.2.127 does not reproduce the issue anymore. It only starts happening after updating to 2.3.3.175

Marking the Globals class as static, and the AppName field as static also works around this. 

Referencing similar code that is included in the same assembly does not cause the issue, see commented out section in MainPage.xaml
Comment 1 rohan bethune 2016-12-07 16:10:27 UTC
Guys

Just to confirm , the attached project that I supplied fails in both XF 2.3.3.175 and 2.3.3.168. The issue has nothing to do with Prism as same issue manifests itself outside of Prism. The project builds successfully in 2.3.2.127 with and without XAMLCompilation but fails >= 2.3.3.168 with XAMLCompilation and using x:Static referencing constants in separate project.

Since we can only move to >= 2.3.3.168 without enabling XAMLCompilation it would be great if we can increase priority of this bug as most prism mobile apps are modular in nature and thus do not confine themselves to just referencing statics within same assembly as defining view.
Comment 2 John Miller [MSFT] 2016-12-07 19:43:19 UTC
@rohan,

I removed all Prism stuff from the Sample Project I attached.
Comment 3 rohan bethune 2016-12-07 22:21:12 UTC
yep my *bad* , didnt look at the attachment and thought it was the same attachment I sent you - but your quite right , issue exists regardless of any third party mvvm frameworks..
Comment 4 Stephane Delcroix 2017-01-24 14:04:03 UTC
I thought this PR https://github.com/xamarin/Xamarin.Forms/pull/642 would have solved this, but apparently not :(

It works for public static string, but fails for public const string
Comment 5 Stephane Delcroix 2017-01-24 14:27:15 UTC
fixed in https://github.com/xamarin/Xamarin.Forms/pull/710
Comment 6 Samantha Houts [MSFT] 2017-03-16 01:09:01 UTC
Should be fixed in 2.3.4-pre2. Thanks!

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