xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 511 forks source link

Issues with hex and integer values in asset catalog color editor #7360

Open leonluc-dev opened 4 years ago

leonluc-dev commented 4 years ago

I am currently having an issue with the handling of color asset values in Visual Studio For Mac. XCode can currently generate color assets in three different syntax: (Examples for a limegreen color #32CD32) Floating point:

"color" : {
        "color-space" : "srgb",
        "components" : {
             "red" : "0.19607",
             "green" : "0.19607",
             "blue" : "0.8039",
             "alpha" : "1.000"
        }
}

Integer:

"color" : {
        "color-space" : "srgb",
        "components" : {
             "red" : "50",
             "green" : "205",
             "blue" : "50",
             "alpha" : "1.000"
        }
}

Hex:

"color" : {
        "color-space" : "srgb",
        "components" : {
             "red" : "0x32",
             "green" : "0xCD",
             "blue" : "0x32",
             "alpha" : "1.000"
         }
}

The XCode designer and iOS runtime can handle all three kinds of syntax fine, but the Visual Studio for Mac asset editor seems to be unable to properly open any asset catalog containing anything other than floating point syntax.

Steps to Reproduce

  1. Create (or import) an iOS Asset Calalog and add a new color set to it
  2. Using a text editor/XCode, change the syntax of the color set to the hex or integer syntax
  3. Open the asset catalog in Visual Studio for Mac

Expected Behavior

Visual Studio shows the colors as expected, no matter if they are in floating point, integer or hex syntax.

Actual Behavior

Only the floating point syntax is rendered properly in the Visual Studio asset editor.

The integer syntax seems to be interpreted incorrectly, leading to unexpected colors (bright pink in the case of the limegreen color used in the examples above)

An asset catalog containing any color set with hex values downright won't open. In such cases an exception is written to the Visual Studio logs (as shown in the Logs paragraph below)

NOTE: While the editor won't open asset catalogs containing hex or integer color sets properly, the Xamarin iOS interface designer, compiler and the iOS runtime still process these color sets as intended.

Environment

=== Visual Studio Professional 2019 for Mac ===

Version 8.3.6 (build 4)
Installation UUID: d0a1bc37-a904-4457-acfa-bbee8fff8206
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)

    Package version: 604000208

=== Mono Framework MDK ===

Runtime:
    Mono 6.4.0.208 (2019-06/07c23f2ca43) (64-bit)
    Package version: 604000208

=== NuGet ===

Version: 5.3.0.6192

=== .NET Core SDK ===

SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: Not installed

=== Xamarin.Profiler ===

Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 11.2 (15526)
Build 11B52

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 13.4.0.2 (Visual Studio Professional)
Hash: e37549bc
Branch: xcode11.1
Build date: 2019-10-07 22:43:23-0400

=== Xamarin Designer ===

Version: 16.3.0.247
Hash: 52eac1a9e
Branch: remotes/origin/d16-3
Build date: 2019-10-03 23:04:28 UTC

=== Xamarin.Android ===

Not Installed

=== Microsoft Mobile OpenJDK ===

Java SDK: Not Found

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 1.4.0.65
Hash: c33b107
Branch: remotes/origin/d16-3
Build date: 2019-10-10 12:15:44 UTC

=== Android Device Manager ===

Version: 1.2.0.116
Hash: d2b2af0
Branch: remotes/origin/d16-3
Build date: 2019-10-10 12:16:06 UTC

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 803060004
Git revision: 081f7b8bbd534cb73bbfb5cff3d9aa4907396a4f
Build date: 2019-10-31 17:10:49+00
Build branch: release-8.3
Xamarin extensions: ade6d975df7634a5d81feda320a6102e5bacf309

=== Operating System ===

Mac OS X 10.15.1
Darwin 19.0.0 Darwin Kernel Version 19.0.0
    Thu Oct 17 16:17:15 PDT 2019
    root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64

Logs

ERROR [2019-11-04 12:32:06Z]: Error while executing command: Open
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
  at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/shared/System/Number.Parsing.cs:1781 
  at System.Number.ParseSingle (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00071] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/shared/System/Number.Parsing.cs:1631 
  at System.Single.Parse (System.String s, System.Globalization.NumberStyles style, System.IFormatProvider provider) [0x00010] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Single.cs:290 
  at System.Convert.ToSingle (System.String value, System.IFormatProvider provider) [0x00009] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Convert.cs:1678 
  at System.String.System.IConvertible.ToSingle (System.IFormatProvider provider) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/String.cs:710 
  at System.Convert.ToSingle (System.Object value) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Convert.cs:1595 
  at MonoDevelop.MacDev.AssetEditor.ColorSetEditorWidget.GetColorComponent (System.Collections.Generic.Dictionary`2[TKey,TValue] components, System.String name) [0x00011] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/ColorSetEditorWidget.cs:186 
  at MonoDevelop.MacDev.AssetEditor.ColorSetEditorWidget.LoadItems (Newtonsoft.Json.Linq.JArray items) [0x00218] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/ColorSetEditorWidget.cs:247 
  at MonoDevelop.MacDev.AssetEditor.AssetEditorWidget.Load (System.String fileName) [0x00172] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/AssetEditorWidget.cs:204 
  at MonoDevelop.MacDev.AssetEditor.AssetFolderViewContent.AddAssetCatalog (Gtk.TreeIter iter, MonoDevelop.Projects.Project project, MonoDevelop.Core.FilePath json) [0x00471] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/AssetFolderViewContent.cs:294 
  at MonoDevelop.MacDev.AssetEditor.AssetFolderViewContent.PopulateAssetCatalogs (MonoDevelop.Projects.Project project, MonoDevelop.Core.FilePath xcassets) [0x0012c] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/AssetFolderViewContent.cs:365 
  at MonoDevelop.MacDev.AssetEditor.AssetFolderViewContent.CreateTreeView () [0x000b0] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/AssetFolderViewContent.cs:147 
  at MonoDevelop.MacDev.AssetEditor.AssetFolderViewContent..ctor (MonoDevelop.Ide.Gui.Pads.ProjectPad.ProjectFolder folder) [0x00082] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/AssetFolderViewContent.cs:90 
  at MonoDevelop.MacDev.AssetEditor.AssetFolderCommandHandler.OpenAssetFolder () [0x00075] in /Users/vsts/agent/2.158.0/work/1/s/MonoDevelop.MacDev/MonoDevelop.MacDev/AssetEditor/AssetFolderCommands.cs:148 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 

Example Project (If Possible)

ColorTestApp.zip

VS bug #1013317

leonluc-dev commented 4 years ago

Update on Windows version:

After some extra testing I can confirm Visual Studio 2019 (16.3) on Windows has similar issues as the Mac edition.

The asset editor on the Windows edition of Visual Studio interprets floating point color values correctly, but integer or hex values are interpreted as a floating point value of 1.0 (leading to hex/integer based colors being rendered as white colors in the asset editor). While the values are interpreted incorrectly, no exceptions occur on opening the hex color sets like on Visual Studio for Mac, though.

Note: A seemingly related issue on Visual Studio for Windows that doesn't occur on the Mac edition is a localization related bug. If the development system formatting region is set to a region where commas are used for decimal notation, floating point values bug out in the same way hex values and integer values do. (Possibly due to Visual Studio interpreting the decimal period as the thousand separator, therefore interpreting the values as integers).

The reverse is also true in such localization scenarios. Any color set edited with the VS2019 asset editor will be generated using a comma as the decimal separator:

"color" : {
        "color-space" : "srgb",
        "components" : {
             "red" : "0,19607",
             "green" : "0,19607",
             "blue" : "0,8039",
             "alpha" : "1,000"
        }
}

The iOS runtime doesn't seem to be able to handle this, causing these color sets to render as a fully black color at runtime.

chamons commented 4 years ago

Thanks for the report. As this is primarily an IDE issue, I'll be creating a bug on their side to look at. You should see responses here hopefully.

If this is closed without a note, please @ me and I'll look into it.