Bug 51566 - XamlC: Cannot use static ImageSource constants for ToolbarItem.Icon anymore
Summary: XamlC: Cannot use static ImageSource constants for ToolbarItem.Icon anymore
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-01-17 08:44 UTC by Michael Rumpler
Modified: 2017-01-17 15:59 UTC (History)
2 users (show)

Tags: AC XamlC
Is this bug a regression?: Yes
Last known good build: 2.3.2.127


Attachments
Repro project (205.55 KB, application/x-zip-compressed)
2017-01-17 08:44 UTC, Michael Rumpler
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 ANSWERED

Description Michael Rumpler 2017-01-17 08:44:22 UTC
Created attachment 19361 [details]
Repro project

# Steps to reproduce

I have all my image sources in a static class and I reference them from there.
In my xaml I have something like:

	<ToolbarItem Icon="{x:Static local:Images.Settings}" />

And in Images.cs:

	public static readonly ImageSource Settings = ImagePath + Device.OnPlatform("Settings_20x20", "Settings_24x24", "");

I use XamlC.

# Expected behavior

It should work.

# Actual behavior

Starting from Xamarin.Forms 2.3.3.152-pre2 I get the error:

> error : Position 46:7. No property, bindable property, or event found for 'Icon'

# Supplemental info (logs, images, videos)

This used to work until Xamarin.Forms 2.3.2.127 and also fails with the most recent 2.3.4.184-pre1.
If I use simple strings for the Icon property, then it works. But as my images have different names and are in different folders I cannot do this.
If I disable XamlC, then it works too.

# Test environment (full version information)

I use Windows 10, VS2015 and Xamarin Cycle 9:

Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Professional

LightSwitch for Visual Studio 2015   00322-40000-00000-AA912
Microsoft LightSwitch for Visual Studio 2015

Microsoft Visual Studio Tools for Applications 2015   00322-40000-00000-AA912
Microsoft Visual Studio Tools for Applications 2015

Visual Basic 2015   00322-40000-00000-AA912
Microsoft Visual Basic 2015

Visual C# 2015   00322-40000-00000-AA912
Microsoft Visual C# 2015

Visual C++ 2015   00322-40000-00000-AA912
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-40000-00000-AA912
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   7.16.00109.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1   14.1.20810.0
ASP.NET and Web Tools 2015.1

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/

Azure App Service Tools v2.9   14.0.20316.0
Azure App Service Tools v2.9

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.0.6000.0
Microsoft Azure Data Lake Tools for Visual Studio

Common Azure Tools   1.8
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

CreateLayoutWizard   1.0
Create layout wizard.

DataFactoryProject   1.0
Microsoft Data Factory Package

Devart Template Editor   1.0.9.0
Editor for T4 and Devart template files with syntax coloring and IntelliSense.

DevExpress.DeploymentTool   1.0
A useful tool for deploying DevExpress assemblies.

GitHub.VisualStudio   2.1.1.5
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

Merq   1.1.3-alpha (74d0861)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft .NET Core Tools (Preview 2)   14.1.20810.0
Microsoft .NET Core Tools (Preview 2)

Microsoft Azure Data Factory Node Node   1.0
Azure Data Factory extension for Visual Studio Server Explorer.

Microsoft Azure HDInsight HQL Service   2.0.6000.0
Language service for Hive query

Microsoft Azure HDInsight Tools for Visual Studio   2.0.6000.0
An integrated development environment for HDInsight application development.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.9.40323.3

Microsoft Azure Tools   2.8
Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.8.40211.2

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   3.5.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

OzCode   1.0
Your road to Magical Debugging. http://www.oz-code.com

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Analysis Services   13.0.1601.5
Microsoft SQL Server Analysis Services Designer 
Version 13.0.1601.5

SQL Server Data Tools   14.0.60525.0
Microsoft SQL Server Data Tools

SQL Server Integration Services   
Microsoft SQL Server Integration Services Designer
Version 13.0.1601.5

SQL Server Reporting Services   13.0.1601.5
Microsoft SQL Server Reporting Services Designers 
Version 13.0.1601.5

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript   1.8.36.0
TypeScript tools for Visual Studio

Visual Studio Tools for Universal Windows Apps   14.0.25527.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   4.3.0.550 (ff5ef6d)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.1.0.19 (3d959b6)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.4.0.67 (6a925ff)
Visual Studio extension to enable development for Xamarin.iOS.

XtraReports package   1.0
XtraReports package
Comment 1 Stephane Delcroix 2017-01-17 14:57:23 UTC
the `static` field `Settings` is of type `ImageSource`, but the `ToolbarItem.Icon` property is of type `FileImageSource`.

an object of type `ImageSource` can not be assigned to a variable of type `FileImageSource`, at least not without casting first.

This used to work, mostly by chance, because prior to 2.3.3, there was not type checking before trying to assign the value. The check, and the failure was deferred to runtime. Now that the StaticExtension is compiled, the type is checked, and in your case invalid, at compile time.

Fix your code to this:

    public static readonly FileImageSource Settings = ImagePath + Device.OnPlatform("Settings_20x20", "Settings_24x24", "");
Comment 2 Michael Rumpler 2017-01-17 15:59:22 UTC
It used to work always and with "it worked" I mean that the correct image has been displayed. The properties are of type ImageSource, but they contained a FileImageSource after all.

However, I'll change all my ImageSource fields to FileImageSource. This seems to work for both Image.Source and ToolbarItem.Icon.

I'll then have to change the code to get rid of the Device.OnPlatform calls anyway. This will be more of a mess.